我有兩個表像如何獲取記錄在有條件的表中兩個表 - PHP和MySQL
table: t1
id|name|type
1 | a |0
2 | b |1
3 | c |0
4 | d |0
...
table: t2
uid|type
4 |1
3 |0
...
我想計數或獲得表t1記錄有型= 1和記錄有ID = UID表t2了type = 1
什麼是計算或獲取記錄在一個查詢像
$type = 1;
$count = mysql_num_rows(mysql_query("Select * .... Where type = $type ")); //$count = 2
$result = mysql_query("Select * ... order by id desc "); // $result include record in table t1 has id (4, 2) b/c order by id desc
編輯的最佳方式: 我做了一個sql嘗試在http://www.sqlfiddle.com/#!2/8847d1/12 但我不能這樣做
我想記錄的結果看起來像(全列有我的上述條件)
id|name|
4 |d |
2 |b |
如何做到這一點感謝
這些表是鏈接的,即有主鍵和外鍵嗎? – jeff
@jeff我在做直接,我不使用外鍵 – freestyle