Jump to content

select distinct values from multiple tables


simplyi

Recommended Posts

Please advise me a sample query or good tutoral to read about selecting distinct values from multimple tables.

 

I have tree tables A,B,C  all linked by id.

 

table B has id of A

table C has id of B

 

If I run a query

 

select a.name, b.address, c. phone then from a,b,c order by a.id

 

then I get a selection form all three tables but I NEED a.NAME to be distinct.

 

Please advise.....

 

Thank you

Link to comment
Share on other sites

Grouping is important when select * distinct

 

   

$res = mysql_query( "SELECT distinct * FROM table_a as a, table_b as b, table_c as group by a.name ORDER BY a.id ASC"); 

 

Otherwise try this assumed method:

 

   

$res = mysql_query( "SELECT distinct name FROM table_a as a, table_b as b, table_c as group by a.name ORDER BY a.id ASC"); 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.