-2
我有2條工作MYSQL語句,我想合併成1個查詢:如何合併這些mysql的語句
從mysql select statement with unique and maximum selects?我:
$sql="SELECT field_a, max(dup_number) as dup FROM table1 GROUP BY field_a"
我的第二個查詢:
$sql="where contacts=0 ORDER BY date LIMIT 3"
這樣一組記錄看起來像示意圖:
ID FIELD A DUP_NUMBER CONTACTS
1 text1 0 1 --
2 text2 0 3 --
3 text2 1 3 --
4 text2 2 3 --
5 text3 0 2 --
我想出:
SELECT *
FROM `table1 `
where max(`DUP_NUMBER `) as dup and `CONTACTS`=1
GROUP BY `FIELD_A`
ORDER BY date
LIMIT 3
當我在phpMyAdmin測試,我得到
#1064 - You have an error in your SQL syntax.
誰能告訴我如何正確地改寫這個?
由於提前,
比爾
你能解釋一下你在做什麼? – 2013-04-10 14:08:53
你說兩個正在查詢。是第二個工作? – 2013-04-10 14:31:02