Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

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

Former Member
0 Kudos

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.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

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....

Regards,

Maha

8 REPLIES 8

Former Member
0 Kudos

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

Former Member
0 Kudos

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....

Regards,

Maha

Former Member
0 Kudos

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

Former Member
0 Kudos

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..

Former Member
0 Kudos

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.

former_member624107
Contributor
0 Kudos

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

graghavendra_sharma
Contributor
0 Kudos

Check the following link for a very good explanation

https://www.sdn.sap.com/irj/sdn/wiki?path=/display/home/difference%2bbetween%2bselect%2bsingle%2band... is better Select single or Select up to 1 Rows]

Former Member
0 Kudos

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