Skip to Content
author's profile photo Former Member
Former Member

Which is better Select single or Select up to 1 Rows?

Hi Guys,

Which is better Select single or Select up to 1 Rows?

As far as i know we should use select single if we use primarykeys and select upto 1 Rows in case of non-primary keys in where clause.

Provide one example to justify you answer.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

8 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jan 11, 2008 at 04:43 AM

    Better to use SELECT SINGLE than using SELECT ... UP TO 1 ROWS since it uses low memory and has better performance."

    Check this WIKI for sample code.

    https://www.sdn.sap.com/irj/sdn/wiki?path=/display/home/difference%2bbetween%2bselect%2bsingle%2band%2bselect%2bupto.

    Regards,

    Maha

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 11, 2008 at 04:43 AM

    HI ,,

    select single is using for testing purpose i mean to check the data is there or not .

    select upto n rows is for extracting data from table .

    so for better performance u can use select single ...

    THX

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 11, 2008 at 04:44 AM

    The 'SELECT SINGLE' statement selects the first row in the database that it finds that fulfils the 'WHERE' clause If this results in multiple records then only the first one will be returned and therefore may not be unique.

    The 'SELECT .... UP TO 1 ROWS' statement is subtly different. The database selects all of the relevant records that are defined by the WHERE clause or lack of, applies any aggregate, ordering or grouping functions to them and then returns the first record of the resultant result set.

    or

    According to SAP Performance course the SELECT UP TO 1 ROWS is faster than SELECT SINGLE because you are not using all the primary key fields.

    select single is a construct designed to read database records with primary key. In the absence of the primary key, it might end up doing a sequential search, whereas the select up to 1 rows may assume that there is no primary key supplied and will try to find most suitable index.

    The best way to find out is through sql trace or runtime analysis.

    Use "select up to 1 rows" only if you are sure that all the records returned will have the same value for the field(s) you are interested in. If not, you will be reading only the first record which matches the criteria, but may be the second or the third record has the value you are looking for.

    The System test result showed that the variant Single * takes less time than Up to 1 rows as there is an additional level for COUNT STOP KEY for SELECT ENDSELECT UP TO 1 ROWS.

    The 'SELECT SINGLE' statement selects the first row in the database that it finds that fulfils the 'WHERE' clause If this results in multiple records then only the first one will be returned and therefore may not be unique.

    Mainly: to read data from

    The 'SELECT .... UP TO 1 ROWS' statement is subtly different. The database selects all of the relevant records that are defined by the WHERE clause, applies any aggregate, ordering or grouping functions to them and then returns the first record of the result set.

    Regards

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 11, 2008 at 04:45 AM

    hi,

    According to SAP Performance course the SELECT UP TO 1 ROWS is faster than SELECT SINGLE because you are not using all the primary key fields.

    select single is a construct designed to read database records with primary key. In the absence of the primary key, it might end up doing a sequential search, whereas the select up to 1 rows may assume that there is no primary key supplied and will try to find most suitable index.

    The best way to find out is through sql trace or runtime analysis.

    Use "select up to 1 rows" only if you are sure that all the records returned will have the same value for the field(s) you are interested in. If not, you will be reading only the first record which matches the criteria, but may be the second or the third record has the value you are looking for.

    plz reward points if useful..

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 11, 2008 at 04:51 AM

    Hi Guru,

    A lot of people use the SELECT SINGLE statement to check for the existence of a value in a database prior to running a large report. Select singles are also used to look up values from a database where that value is going to be constant for the duration of the program run, or the value is being used to validate some user entry.

    Other people prefer to use the 'UP TO 1 ROWS' variant of the SELECT statement.

    So what's the difference between using 'SELECT SINGLE' statement as against a 'SELECT .... UP TO 1 ROWS' statement ?

    If you're considering the statements

    Code:

    SELECT SINGLE field

    INTO w_field

    FROM table.

    and

    Code:

    SELECT field

    INTO w_field

    FROM table

    UP TO 1 ROWS.

    ENDSELECT.

    then looking at the result, not much apart from the extra ENDSELECT statement. Look at the run time and memeory usage and they may be worlds apart.

    Why is this ?? The answer is simple.

    The 'SELECT SINGLE' statement selects the first row in the database that it finds that fulfils the 'WHERE' clause If this results in multiple records then only the first one will be returned and therefore may not be unique.

    The 'SELECT .... UP TO 1 ROWS' statement is subtly different. The database selects all of the relevant records that are defined by the WHERE clause or lack of, applies any aggregate, ordering or grouping functions to them and then returns the first record of the resultant result set.

    Reward if useful.

    Thankyou,

    Regards.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jan 11, 2008 at 04:58 AM

    Hi...

    When all the KEY fields (of the table from which we are selecting) are available for WHERE condition ,it is better to use select single.

    Otherwise use select UPTO 1 ROWS

    Regards,

    Sheeba

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 19, 2008 at 07:53 AM
    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 19, 2008 at 08:09 AM

    Hi,

    SELECT UP TO 1 ROWS is faster than SELECT SINGLE *

    SELECT SINGLE * will check all the possible records and finally displays only one record.

    SELECT UP TO 1 ROWS will display only the first possible record.

    Regards,

    Chandru

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.