Reputation: 200
i want get a SQL like the pic~
now i want get the result by Top 3 projectId (4,3,2) total 8 result.
so how can i mody my sql?
( the SQL in real project is so complex~,about 10 my DBTable and 10 SAP table~ i concerned about efficiency so i don't want use temporary table)
can u help me~?
Upvotes: 1
Views: 47
Reputation: 263883
if you are using SQL Server
, use TOP
SELECT *
FROM table1
WHERE ProjectID IN
(
SELECT DISTINCT TOP 3 ProjectID
FROM table1
ORDER BY ProjectID DESC
)
ORDER BY ProjectID Desc
Upvotes: 2
Reputation: 34387
If using MySQL then:
SELECT * FROM TABLE1
ORDER BY PROJECTAID ASC
LIMIT 10;
Upvotes: 0