How to select 1 record in DB2

5 pts.
Tags:
IBM DB2
SELECT statement
As usual, I often use: select top 1 * from table but in DB2, I can't. I use the Toad tool to input SQL statement. Does anyone have a solution? Please share it with me. Tkanks a lot!

Answer Wiki

Thanks. We'll let you know when a new response is added.
SELECT * FROM <TABLE_NAME>
FETCH FIRST 1 ROW ONLY

-- FOR MULTIPLE ROWS
SELECT * FROM <TABLE_NAME>
FETCH FIRST <NUM> ROWS ONLY

Please let me know if you need any information

-Vijay Kanth

Hello,

In a relational design, you first have to answer the question “first what?”
The previous example will return 1 row, but you will never know which row.
So don’t forget ORDER BY and WHERE clauses.

Steve

Discuss This Question: 3  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Ejsongy
    What if the query is a sub-select?
    10 pointsBadges:
    report
  • runny

    if in a table a perticular coloumn value is same in no of rows, then how to get tha row count.

    10 pointsBadges:
    report
  • TomLiotta
    ...how to get tha row count.   Use the COUNT() function. If there is some reason that the same value in multiple rows makes a difference to you, please explain what the difference is. And that probably would mean that you should open a new question because that doesn't seem to be part of this question thread.   Tom
    125,585 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following