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.
Search Query
Moderator: General Moderators
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.
go here for more:
http://www.mysql.com/doc/en/JOIN.html
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());http://www.mysql.com/doc/en/JOIN.html