sql conditional statement

Posted on 2014-08-19
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

    select top 1 *
    from tbl1
    where groupid in (4,2)
    order by groupid desc

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
    In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
    Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
    Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

    761 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

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now