we can select data in three tables in one query | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 13

we can select data in three tables in one query

31st Oct 2016, 1:47 AM
Saurav Saini
Saurav Saini - avatar
4 Answers
+ 11
@esteban juazez, sir you can define how to use three tables in one query? I am able only two tables with JOIN.
2nd Nov 2016, 5:05 PM
Saurav Saini
Saurav Saini - avatar
+ 2
yes You can, if You are using SQL You should take a look at joins. with joins You can select information for many tables using their index and row id.
31st Oct 2016, 2:07 AM
Esteban Juarez Rodriguez
Esteban Juarez Rodriguez - avatar
+ 1
well lets say that u have 3 tables, the first table lets name it Users has the users information for a forum like their username,password,email and ofcourse the userId. The second table lets name it threads has the threads that u have in ur forum so it has the columns title,message,likes and ofcourse the threadId. Finally in order to link both of the tables u have a final table lets name it userThread it has only 4 columns userThreadId,date,userId and threadId. Now u have 3 tables even if this is a bad example because u can just add the column userId to the table threads but this is just an example :v. in order to retrive the thread title, the message, the username and the date u Will have to use joins. right now i dont have access to a SQL editor so the statement below can be wrong but i think is something like this. select threads.title, threads.message, Users.username, userThread.date from userThread natural join Threads natural join Users; in this case i'm using natural join because the name of my index columns is the same so the data base is able to identify the index by itself and do the where clause that is needed.
2nd Nov 2016, 6:02 PM
Esteban Juarez Rodriguez
Esteban Juarez Rodriguez - avatar
+ 1
yes you can, if you use SQL joins according to condition
14th Sep 2017, 5:16 AM
vishal jain