willsonchan
willsonchan

Reputation: 200

How Can i conditions of the query as a column in the data

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~?enter image description here

Upvotes: 1

Views: 47

Answers (2)

John Woo
John Woo

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

Yogendra Singh
Yogendra Singh

Reputation: 34387

If using MySQL then:

   SELECT * FROM TABLE1 
   ORDER BY PROJECTAID ASC
   LIMIT 10;

Upvotes: 0

Related Questions