Page 1 of 1

SQL query...any one?

Posted: Thu Feb 23, 2006 3:34 am
by gotlisch
Hi Guys,

I'm having some problems figuring out how to construct a sql query doing the following:

Tables: Company, Contact.

"SELECT all companies AND match the corresponding Contact.
But a company might also not have a contact but should still
be returned."

This is what I have at the moment, but as you can see it wont return companies without a contact:

Code: Select all

SELECT company.name.....ect FROM company,contact WHERE company.name = contact.company AND company.phone LIKE '.$search_string;

Cheers

Mikael

Posted: Thu Feb 23, 2006 4:38 am
by khaki_monster
i assumed that you've assigned some id's('ID') as a key(let say "Primary Key"). it would be easy to query providing the keys for the tables: Company, Contact.

Code: Select all

"Select Company.name, Contact.phone From Company left join Contact On Company.id = Contact.id"
i hope this work :)


cheerz!