Page 1 of 1

Select from 2 different tables

Posted: Sun Feb 21, 2010 2:06 pm
by easinewe
Hello,
I am creating a search function and would like this two work with 2 or more tables; Dog Catalog and portfolio in this example. What am I doing wrong here?

"SELECT * FROM portfolio, Dog Catalog WHERE
Dog Catalog.title LIKE '%$find%' or
portfolio.client LIKE '%$find%'";

I get errors whenever I try to echo a result.

Any help would be appreciated.

Re: Select from 2 different tables

Posted: Mon Feb 22, 2010 4:19 am
by aravona
you need to use a join: http://www.w3schools.com/SQl/sql_join.asp

Code: Select all

"SELECT * FROM portfolio, Dog Catalog WHERE 
Dog Catalog.title LIKE '%$find%' or 
portfolio.client LIKE '%$find%'";

Code: Select all

SELECT *
FROM portfolio
INNER JOIN Dog Catalog
ON portfolio.column_name = Dog Catalog.column_name (needs to be the PK and FK)
WHERE Dog Catalog.title LIKE '%$find%' or 
portfolio.client LIKE '%$find%'
That should work with your keys in. But read up on joins first so you have more of an idea at whats going on :)