Select value from first row where

Posted on 2010-01-05
Last Modified: 2012-05-08
I have a table with following columns: Id,  AId, BId
I would like to select the value in AId from the first row where BId=@BId. How do I do that?
Question by:johnkainn
    LVL 4

    Accepted Solution

    select top 1 ald from table where bld=@bld
    LVL 26

    Assisted Solution

    select top 1 AId
    from yourTable
    where  BId=@BId
    LVL 60

    Assisted Solution

    "first row" is ambiguous...first has to be based on you'd need an order by

    select top 1 AId
    from yourTable
    where  BId=@BId
    order by AId

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    by Mark Wills PIVOT is a great facility and solves many an EAV (Entity - Attribute - Value) type transformation where we need the information held as data within a column to become columns in their own right. Now, in some cases that is relatively…
    I've encountered valid database schemas that do not have a primary key.  For example, I use LogParser from Microsoft to push IIS logs into a SQL database table for processing and analysis.  However, occasionally due to user error or a scheduled task…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    754 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

    19 Experts available now in Live!

    Get 1:1 Help Now