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: 

abap,general

Former Member
0 Kudos

1)what is the disadvantage of using 'select single'?

2)when we have to go for 'select single'&select.... up to 1 rows?

3)why we have to use only primary key fields on 'select single' statement?

5 REPLIES 5

p291102
Active Contributor
0 Kudos

Hi,

Difference Between Select Single and Select UpTo One 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.

Mainly: to check if entries exist.

Thanks,

Shankar

Former Member
0 Kudos

hi

good

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.

THNAKS

MRUTYUN^

Former Member
0 Kudos

select single is fetching only first row which satisfy the where condition. so if you are mentioning the primary key fields in the where clause then it must satisfy only one row which satisfy the where condition because primary keys are unique. In select upto one row we can use when we can not specify full primary key value in the where clause .. here system reads reads all the values as per where clause (because you are not assigning full primary key value so it may have duplicate entries ) and return any one of them.

regards

shiba dutta

Former Member
0 Kudos

Srinivas,

Welcome to SDN.

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

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

3.In case of select single....select statement does not consider grouping and sorting.which ever record matches with conditions present in where clause..that will be filled in corresponding work area.. So here the condition is must. So you have to specify the primary key condition

If you find it useful mark the points

~~Guduri

Former Member
0 Kudos

hi,

1ans).In where clause you have to specify the primary key(to ensure unquie value).

if you dont know primary key,then problem arises.(i think so).

2Ans.)

hi,

The behaviour depend on some other factors. For example, if the table has single-record buffering, the buffer can be used only for accesses with SELECT SINGLE nd other SELECT statements access database directly.

The results are unpredictable since we do not know about the order in the database catalog. After droping and re-creating the table the results of the two queries may change.

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

3ans).

To read all columns of a single line from a database table,use the select sinle statement.

The result will be single line statement. To make sure you retrieve desired unique single record

You must link all the fields which form the primary key of the database table.

General ex: area code,surnames,pincode.

regards,

sri

pls: award points.