Page 1 of 1

Search Query

Posted: Mon Aug 11, 2003 1:03 pm
by jamrop
Hey

Is it possible to search from 2 tables in mysql?

e.g. i have an advert table and an announement table.
I want to try and make a search form , that will query the database of keywords and search the 2 tables

is that possible?

i know that one table would be

select * from advert where description like "%blah%";

but not sure if you can do 2 tables. They do not have a relationship.

Posted: Tue Aug 12, 2003 2:51 pm
by xisle
as long as the tables live in the same database you can use a join, otherwise use two mysql connections.
Here is a straight two table example, be sure to check a common key within your 'WHERE' statement to avoid duplicate rows.

Code: Select all

$query="SELECT DISTINCT stories.story_id, stories.type, stories.publish, library.story_ID, library.headline, library.byline, library.entrydate,
FROM stories, library 
WHERE stories.story_id= library.story_ID 
&& stories.publish ='Y' 
ORDER by entrydate DESC LIMIT 10";
$result=mysql_query($query) or die(mysql_error());
go here for more:
http://www.mysql.com/doc/en/JOIN.html