[Last Call] Learn how to a build a cloud-first strategyRegister Now


sql conditional statement

Posted on 2014-08-19
Medium Priority
Last Modified: 2014-08-19
groupid      measure1      measure3      measure4
2              89                     78                     77
4             87                    77                    77

want to select from tbl1 and return only 1 row
select * from tbl1 where groupid in (select groupid = case when groupid = 4 then 4 else 2 end from tbl1)  - this is still returning 2 rows, I just want 1. I want the 1 with 4 and if 4 isn't there I'll take 2
Question by:elucero
1 Comment
LVL 21

Accepted Solution

Dale Burrell earned 2000 total points
ID: 40271363
select top 1 *
from tbl1
where groupid in (4,2)
order by groupid desc

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question