hello all:

i am using mySQL and I created a few tables and I am learning how I can use the SQL query on multiple tables. The following are the results which are quite confusing and it will be helpful if someone can help me understand as to how this works. Thanks!

select distinct names.contact_id,firstname,lastname,email,telephonework,telephonehome from names,email,telephones where names.contact_id=email.contact_id=telephones.contact_id;

the query results in the correct result that I was looking for.

But minor changes in the query above as follows leads to wrong results.

select distinct names.contact_id, firstname,lastname,email,telephonework,telephonehome from names,email,telephones where names.contact_id,telephones.contact_id=email.contact_id;


select distinct names.contact_id,firstname,lastname,email,telephonework,telephonehome from email,telephones,names where email.contact_id=telephones.contact_id=names.contact_id;

if you can tell me why this differs.. it will be helpful. Thanks!

8 Years
Discussion Span
Last Post by jbisono

In the first select statement, into the where clause after names.contact_id you have a "," that is wrong.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.