Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search scripts

Status
Not open for further replies.
May 22, 2002
63
0
0
GB
Hi,

I've got a problem with a search I am trying to perform in MySQL:

I have a company table and a contacts table. They are linked by a table called contactassocs which simply assigns an ID to an entry where the companyId and contactID and entered. This is the assocID.

I want to do a 'like' search so users of a system I am coding can simply search all fields and return entries that match within the contacts database system.

However the problem I have is where a company has been setup and no contacts added to it - hence no relationship established in the contactassocs table the SQL that specifies the joins between tables returns no results - even if company fields do match the search.

Short of writing a complex PHP script to do loads of different iterations of the SQL query, is there a single sql query I can write that will satisfy an output if there is a match in either the company OR contacts table, even if I explain the join within the sql?

Cheers,

Anders
 
Sounds like you need to do an outer join against the association table.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top