New Poll – What do you use to select one record from DB?

By | March 12, 2014 | Polls | 1,957 | 3

New Poll is now available with an question – What do you use to select one record from DB

New Poll

When there is a need to get exactly one record from DB, we have couple of choices – Use SELECT SINGLE or SELECT UP TO 1 ROWS. There have been lot of questions around when to use which. So, I think would be a good to get your take on it

The poll question is:

What do you use to select one record from DB?

Options are:

I can understand that you might be using both of them, but select the one you use most often.

Cast your vote here:

What do you use to select one record from DB?

  • select SINGLE (80%, 2,265 Votes)
  • select UP TO 1 ROWS (20%, 554 Votes)

Total Voters: 2,820

Loading ... Loading ...

Tags

Like It? Share!!

Don't miss an Update

Get notified of the new post, right into your inbox

Naimesh Patel{274 articles}

I'm SAP ABAP Consultant for more than a decade. I like to experiment with ABAP especially OO. I have been SDN Top Contributor.
Follow :

Explore all of his 274 articles.

Load comments

3 Comments

  • Kjetil Kilhavn

    What to use depends on the circumstances. It is not correct to use SELECT SINGLE if you don’t have the full key. If I have the full key I always use that. But there are other cases. Sometimes I use SELECT … UP TO 1 ROWS, but I often don’t restrict the number of rows, because I want to be able to issue a warning or error message if there is more than one row when I expect exactly one.
    So the answer which is missing in your alternatives is «it depends» (on the use case).

  • Hello Kjetil,

    I agree with you – what you use is depends on the scenario. But majority of time, developers tend to use of the other, even though scenarios is different – with key or without key still using either of the method.

    Issuing a warning / error if you find more than expected is, I believe would be a different context, but it would be a great idea to make sure users use the software the way they supposed to 🙂

    Thanks,
    Naimesh Patel

  • Akira

    If you have the full key, there’s no question not to use SELECT SINGLE statement.

    Now for non-full key, aside from removing that error message in the SAP code checker, the only reason I see for using SELECT UP TO 1 ROWS is when you want to retrieve a pre-processed record.

    Example would be you need to retrieve the last item of a Purchase order (EKPO). The code would be something like SELECT UP TO 1 ROWS WHERE ebeln = docnum ORDER BY ebelp DESCENDING.

    The result will be the same for both select statement if no pre-processing is involved but SELECT SINGLE is faster so…

Comments on this Post are now closed. If you have something important to share, you can always contact me.

You seem to be new here. Subscribe to stay connected.