27

I have two tables:

services

  • id
  • client
  • service

and

clients

  • id
  • name
  • email

How to list table service and bring together the customer name that the customers table? field customer services in the table has the id of the customer at the customer table,

I appreciate the help from you now

Timwi
  • 65,159
  • 33
  • 165
  • 230
  • 1
    Notice there are several different types of joins which are subtly different. The answers have already mentioned `JOIN`, `LEFT JOIN` and `INNER JOIN`; there is also `LEFT OUTER JOIN` and `RIGHT OUTER JOIN` and possibly some more that I don’t know about. You can probably google these names to find out what the differences are. – Timwi Aug 21 '10 at 04:13
  • 4
    @Timwi: LEFT JOIN and LEFT OUTER JOIN are the same - you don't need to specify OUTER in the syntax. This is a [good link showcasing joins](http://www.codinghorror.com/blog/2007/10/a-visual-explanation-of-sql-joins.html) – OMG Ponies Aug 21 '10 at 04:19
  • 1
    The link "showcasing joins" above is terrific for those of us who like visual representations. Various JOINs are shown as Venn diagrams. Really great. Made it simple. – Mike_Laird Jan 27 '13 at 21:57

4 Answers4

39
SELECT * FROM table1 LEFT JOIN table2 on table1.id = table2.id
GWW
  • 43,129
  • 11
  • 115
  • 108
18
SELECT ...
FROM services AS s
JOIN clients AS c
  ON s.client = c.id
WHERE ...
Daniel Vandersluis
  • 91,582
  • 23
  • 169
  • 153
3
SELECT ...
FROM services AS s
INNER JOIN clients AS c
  ON s.client=c.id
Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
0

Try this,

SELECT * from services as s INNER JOIN clients as c on s.id=c.id 
Sat Siva
  • 9
  • 6