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

diff b/w select single * & select upto 1 rows?

pls give the differnece diff b/w select single * & select upto 1 rows? But i heard that select upto 1 rows with fetch the data based on the gn condition and perform aggregation on it and displays the topmost record? is that true? pls give ur review?

Thanks in advance....

Add a comment
10|10000 characters needed characters exceeded

Related questions

10 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Jan 08, 2007 at 04:11 PM

    Hi Balaji,

    The <b>SELECT SINGLE</b> statement selects the first row in the database based on 'WHERE' condition

    The <b>SELECT .... UP TO 1 ROWS</b> The database selects all of the records based on WHERE conditoins and then returns the first record of the result.for this we have to use endselect.

    https://www.sdn.sap.com/irj/sdn/forumsearch

    difference-between-'select-single--'-and-'select-u

    difference-between-select-single-and-select-upto-o

    Thanks

    Vikranth khimavath

    Message was edited by:

    Khimavath Vikranth

    Message was edited by:

    Khimavath Vikranth

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 08, 2007 at 04:14 PM

    HI,

    Select single * : fetches the first record which satisfies in ur where condition even the multiple records r satisfy.

    select upto 1 row: fetches only the first record in the table.

    regards

    CNU

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 08, 2007 at 04:16 PM

    Hi,

    The Major difference between Select Single and Select UPTO 1 rows is The Usage Of Buffer for each.

    Select Single will search for all the satisfied data and bring all that data into Buffer and later it will give to that data to the program.

    Select UPTO 1 Rows will end the search after getting the 1st satisfied record and gives that record to the program.

    Thus Select Single will take much processing time when compare with Select UPTO 1 rows.

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 08, 2007 at 04:24 PM

    This question has been asked many times before in the forum and the answer is invariably the same. Please do a search on "<b>subtly</b>".

    Rob

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 08, 2007 at 06:48 PM

    HI,

    For Performance point of view:

    Select Single has only one communication with database. And Select Single upto one Row has two cmmunications with database.

    Ashvender

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 08, 2007 at 06:55 PM

    difference is...

    say MARA table where in u will have different materials...

    so u can use select single matnr ......

    now say mseg where in u will have same material many times....

    so u use select up to 1 rows......

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 08, 2007 at 06:57 PM

    What is the difference between SELECT SINGLE and SELECT ... UP TO 1 ROWS?

    SELECT SINGLE returns the first matching row for the given condition and it may not be unique, if there are more matching rows for the given condition.

    SELECT ... UP TO 1 ROWS retrieves all the matching records and applies aggregation and ordering and returns the first record.

    Inorder to check for the existence of a record then it is better to use SELECT SINGLE than using SELECT ... UP TO 1 ROWS since it uses low memory and has better performance."

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 08, 2007 at 06:57 PM

    Report Z_Difference

    Message-id 38

    Line-Size 80

    Line-Count 0

    No Standard Page Heading.

    Start-Of-Selection.

    Data: w_Single type Posnr,

    t_Rows type standard table of Posnr initial size 0

    with header line.

    select single Posnr

    from zDifference

    into w_Single.

    Select Posnr

    into table t_Rows

    from zDifference

    up to 1 rows

    order by Posnr descending.

    Write :/ 'Select single:', w_Single.

    Skip 1.

    Write :/ 'Up to 1 rows :'.

    Loop at t_Rows.

    Write t_Rows.

    EndLoop.

    *******************************************

    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.

    Mainly: to check if entries exist.

    You can refer to the below link..

    http://www.sap-img.com/abap/difference-between-select-single-and-select-upto-one-rows.htm

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 09, 2007 at 03:28 AM

    Hi balaji,

    When u use SELECT SINGLE * , though you have lot of records,it will fetch the first record based on your condition.It never read all the matching records.

    But where as in SELECT ....UPTO 1 ROW.It will read all the records in buffer but take the first record.

    Conclusion is select single * is good in performance wise.

    Pls. reward for useful .

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 10, 2007 at 04:41 AM

    SELECT UP TO 1 ROWS allows you to have the database sort first, and then return the first match. For example,

    SELECT * from USR02 UP to 1 ROWS

    where trdat = sy-datum

    order by LTIME descending.

    ENDSELECT.

    This gives the most recent user to logon today.

    SELECT SINGLE should only be used if you have the full key. Performance is similar, but the program is more readable.

    Neither SELECT SINGLE or SELECT UP TO 1 ROWS should be used for testing if a record exists. It is faster to use SELECT COUNT( * ) WHERE... and check sy-subrc (do not supply an INTO field).

    Regards

    Michael

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Select single * : fetches the first record which satisfies in ur where condition even the multiple records r satisfy.

      select upto 1 row: fetches only the first record in the table.

      The Major difference between Select Single and Select UPTO 1 rows is The Usage Of Buffer for each.

      Select Single will search for all the satisfied data and bring all that data into Buffer and later it will give to that data to the program.

      Select UPTO 1 Rows will end the search after getting the 1st satisfied record and gives that record to the program.

      Thus Select Single will take much processing time when compare with Select UPTO 1 rows.

      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

      For Performance point of view:

      Select Single has only one communication with database. And Select Single upto one Row has two cmmunications with database.

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.