-5

Please help me in joining 3 and more tables in SQL with simple syntax. I was not able to find the exact syntax for this.

halfer
  • 19,471
  • 17
  • 87
  • 173
  • There you go http://www.w3schools.com/sql/sql_join_inner.asp – sagi Feb 22 '16 at 09:12
  • Hi Mureinik, I tried with these links. https://technet.microsoft.com/en-us/library/ms191430%28v=sql.105%29.aspx http://www.codeproject.com/Articles/435694/Understanding-Table-Joins-using-SQL#_articleTop – Kanagaraj Subramaniam Feb 22 '16 at 09:23
  • Be more concrete. Give us an example SQL not the pages you visited. – wumpz Feb 22 '16 at 09:29

2 Answers2

1

Assuming that you have table 1, table 2 and table 3. Let´s create a simple example.

table 1: employees: id, department_id, first_name, last_name, salary...

table 2: departments: id, location_id, department_name...

table 3: locations: id, city...

department_id and location_id are foreign keys. Employees have a department_id and Departments have a location_id. You need this foreign keys in order to JOIN different tables.

Then you can use this query to join the tables:

SELECT first_name, salary, department_name, city
FROM departments JOIN employees USING (department_id)
JOIN locations USING (location_id)
GROUP BY first_name, salary, department_name, city;

If you want to learn more about different kind of joins I found a good explanation here.

Hope it helps!

Community
  • 1
  • 1
Diego Vidal
  • 954
  • 7
  • 21
-2

Assuming that there are three tables x,y,z:

Table x - id,Column1
Table y - id,Column2
Table z - id, Column3

Try the script below:

select x.column1,y.column2,z.column3 from x
inner join y on x.id = y.id
inner join z on x.id = z.id
halfer
  • 19,471
  • 17
  • 87
  • 173
Webdev
  • 585
  • 4
  • 23