SQL query...any one?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
gotlisch
Forum Newbie
Posts: 23
Joined: Wed Jan 11, 2006 8:37 am

SQL query...any one?

Post 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
User avatar
khaki_monster
Forum Commoner
Posts: 73
Joined: Tue Oct 11, 2005 12:36 am
Location: Philippines
Contact:

Post 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!
Post Reply