Reply to topic
SQL JOINT Query
Medrise


Joined: 28 Jan 2009
Posts: 1
Reply with quote
I have 3 tables that I joining to get the results that I need, but my question is when I joing the table I get all the results I want, but the first table that contains some basic information repeats everytime I display the query.

For example say I have these 2 tables.

tbl_customer tbl_phone
-CustID -PhoneID
-Name -CustID
-Address -PhoneNumber

When I join both table if the customer has more than one phone I will get this.

0001 Jon Doe 123 Post Rd. 732-555-5555
0001 Jon Doe 123 Post Rd. 732-555-5111
0001 Jon Doe 123 Post Rd. 732-555-5100

Is there a way just to get the phone number "in this case" and not repeat the other data?
Josh
Forum Regular

Joined: 01 Apr 2004
Posts: 1047
Location: Felton, Delaware
Reply with quote
I believe the GROUP BY clause maybe what you're looking for...

Code:
SELECT t1.CustID, t1.Name, t1.Address, t2.PhoneNumber
FROM tbl_customer AS t1
INNER JOIN tbl_phone AS t2 ON t1.CustID=t2.CustID
GROUP BY t1.CustID
SQL JOINT Query
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT  
Page 1 of 1  

  
  
 Reply to topic