Mysql query

$query2 =(“SELECT,, clientenquiry.address,
contacts.first, contacts.last,,,, installmentmsg.message
FROM clientenquiry, contacts, installmentmsg
WHERE name like ‘%$query%’ OR company like ‘%$query%’ OR address like ‘%$query%’
OR first like ‘%$query%’ OR last like ‘%$query%’
OR email like ‘%$query%’ OR message like ‘%$query%’”);

this query is not working and showing msg " Column ‘address’ in where clause is ambiguous" " Column ‘name’ in where clause is ambiguous" and so on.
i want to create a search engine and i have different tables with different data but same field names.
can any1 plz help me??:rolleyes:

Its pretty straight forward. You are joining three tables: clientenquiry, contacts and installmentmsg. One or more of these tables have similarly named columns hance inside the where clause you have to specify <tabe name>.<column name> to resolve the ambiguity, just the way you are doing in the select clause. Eg:

WHERE [B]clientenquiry.[/B]name like '%$query%' 
OR [B]clientenquiry.[/B]company like '%$query%' ...

PS: You need to specify additional where clause items to join the three tables together.

Hi Anita,

The following link on table joining might be useful:

You need to be able to establish a link between the different tables. So if you have a table called contacts with a contact_id field and a table called clientenquiry which also uses contact_id then you can join the tables there and get contact and enquiry details from a single database query.

Hope that helps.

Hi Anita. Is there a relation between those three tables? Can you post show create table for all three?

Hi Anita, In that case you need to declare your table names in the the WHERE clauses as well. The fields address, name and which ever other columns, are obviously represented in more than one table