2017-06-01 58 views

回答

0

我認爲你可以在MAX爲該組JOIN解決這個問題:

SELECT * FROM sections_content as t 
JOIN 
    (
     SELECT MAX(id) as id 
     FROM sections_content AS tbl 
     GROUP BY 
      tbl.policyName, 
      tbl.statecode 
    ) AS maxId 
    ON maxId.id=t.id 
+0

這個工程!非常感謝 – Patcharapan

0

我認爲你可以使用ORDER BYLIMIT關鍵字,以獲得最大數量。

Exp:有桌子; 表1表2與您的數據庫一樣。檢查下面的查詢。

SELECT table1.id, table2.statecode, table2.policyname, sections_content.student_lga_of_origin 
FROM table1 
JOIN table2 
ON table1.policyname = table2.policyname 
ORDER BY table1.id DESC 
LIMIT 1 
OFFSET 1 
相關問題