Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: SQL Server
Expertise: Beginner
Jul 6, 2000



Application Security Testing: An Integral Part of DevOps

Multiple Entries That Meet Criteria

How can I pull just the first match to a query? We have a database of jobs in process:
jobno 12345
op# 10 shear %complete 100
op# 20 punch % complete 90
op# 30 deburr %complete 0
op# 40 timesave %complete 0
jobno 67890
op# 10 shear %complete 100
op# 20 punch % complete 100
op# 30 deburr %complete 90
op# 40 timesave %complete 0
I want my query to pull just the first occurrence of WHERE %complete < 100. Right now, my results return op#20, 30, and 40 for jobno 12345 and op#30 and 40 for jobno 67890. I want the results to be just op#20 for jobno 12345 and op#30 for jobno 67890.

For a table called TestTable with the columns JobNo, OP, and PercentComplete and the above data, this query returns the JobNo and the maximum PercentComplete entry where the PercentComplete is less than 100:

SELECT JobNo,  MAX(PercentComplete) AS PercentComplete 
FROM TestTable
WHERE PercentComplete < 100
Returns this data set:
JobNo      PercentComplete 
---------- --------------- 
12345      90
67890      90
DevX Pro
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date