How to find FIRST matching value from the table ,

  • Hi Team ,

    How to find first matching value from the table ,

    I need to get the first Australia amount 5000 ?

    How to write the query

    DischargeAmont

    Duabi 1000

    Singapore 2000

    Australia 5000

    Canada 9000

    China 12000

    Duabi 6500

    Singapore 1456

    Australia 123

    Canada 356

    China 1223

    Duabi 4332

    Singapore 1121

    Australia 4225

    Canada 7665

    Thanks,

  • Could you post DDL of the table (first link in my sig block shows you how), there might be something missing from your question which will help to get the right answer

    -------------------------------Posting Data Etiquette - Jeff Moden [/url]Smart way to ask a question
    There are naive questions, tedious questions, ill-phrased questions, questions put after inadequate self-criticism. But every question is a cry to understand (the world). There is no such thing as a dumb question. ― Carl Sagan
    I would never join a club that would allow me as a member - Groucho Marx

  • In addition to needing more details as Stuart said, tables in sql have no concept of "first" or ordering of any kind. "First" indicates some sort of ordering to know which one is first. First could mean the largest value in amount (like what you posted), or it could mean the first row inserted, or it could be the first alphabetically or....

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • SQL may not Sean, but it is posted in Reporting Services, which does. However as you rightly say the order needs to be established for the rows returned so that "first" returns the correct data every time.

    -------------------------------Posting Data Etiquette - Jeff Moden [/url]Smart way to ask a question
    There are naive questions, tedious questions, ill-phrased questions, questions put after inadequate self-criticism. But every question is a cry to understand (the world). There is no such thing as a dumb question. ― Carl Sagan
    I would never join a club that would allow me as a member - Groucho Marx

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply