How to get record in one table with conditional in two tables - PHP and Mysql -
i have 2 table like table: t1 id|name|type 1 | |0 2 | b |1 3 | c |0 4 | d |0 ... table: t2 uid|type 4 |1 3 |0 ... i want count or records in table t1 have type = 1 , records have id = uid in table t2 has type = 1 best way count or record in 1 query like $type = 1; $count = mysql_num_rows(mysql_query("select * .... type = $type ")); //$count = 2 $result = mysql_query("select * ... order id desc "); // $result include record in table t1 has id (4, 2) b/c order id desc edit: made sql try in http://www.sqlfiddle.com/#!2/8847d1/12 can't that want records result (all column have above conditional) id|name| 4 |d | 2 |b | how thank select t1.id,t1.name t1 left join t2 on t1.id = t2.uid t1.type = 1 or t2.type = 1