Search code examples
phpmysqlgetsql-like

How to select two record from two different table with one query in mysql


How to select two record from two different table with one query in mysql?

for a search query I'm using

$search = $_GET['gd']
$arama_sonuc = mysql_query("select * from mp3 where baslik like '%$search%'");

well it's ok. it shows me results from mp3 table. but with same query I need to search something on HABERLER table too.. how can I do?


Solution

  • Use the UNION command http://dev.mysql.com/doc/refman/5.0/en/union.html

    select * from mp3 where baslik like '%$search%'
    UNION 
    select * from HABERLER where baslik like '%$search%'
    

    (presumably they have the same number of columns and the same types, etc)