I want to making a MySQL query that gets a link from table1 and checks to see if this link exists in table2 and table3.
Now I am doing 2 queries, but I would like to combine the 2 query into 1, and guarantee 10 results are returned? (After the first, currently, if mysql_num_rows($rez)>0, the return result would be less 10)
Thanks.
$result = mysql_query("SELECT id,link FROM table1 WHERE Order By id DESC LIMIT 0,10");
while ($row = mysql_fetch_array($result)){
$rez = mysql_query("(SELECT link FROM table2 WHERE link='".mysql_real_escape_string($row['link'])."') UNION (SELECT link FROM table3 WHERE link='".mysql_real_escape_string($row['link'])."')");
if(mysql_num_rows($rez)==0){
//do stuff with $row['link'];
}
}
You can use sub-queries to acomplish this
SELECT id, link FROM table1 WHERE (link IN (SELECT link FROM table2)) OR (link IN (SELECT link FROM table3)) LIMIT 10My format might be slightly off, and it seems like there’s probably a better way to do that query, but check out sub-queries as I think those will get you in the direction you want to go