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: 

difference between query select single and select upto 1 rows

Former Member
0 Kudos
1,000

can u plz help me in telling out the difference between query select single and select upto 1 rows

10 REPLIES 10

Former Member
0 Kudos
256

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.

Regards

Rusidar

Former Member
0 Kudos
256

Hi,

<b>Difference Between Select Single and Select UpTo One Rows</b>

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.

<b>select single</b>

The result of the selection should be a single entry. If it is not possible to identify a unique entry, the system uses the first line of the selection. For e.g.

that is It fetches single record from the database, based on the condition you specified in the where clause.

DATA : ITAB TYPE ZREKHA_EMP.

SELECT SINGLE *

FROM ZREKHA_EMP

INTO ITAB

WHERE EMPNO = ‘00101’ AND

DEPTNO = ‘0010’.

WRITE : / ITAB-EMPNO, ITAB-EMPNAME .

<b>select upto n rows</b>

Fetches first record if the condition specified in the where clause is satisfied, otherwise it doesn't fetch any record

SELECT field

INTO w_field

FROM table

UP TO 1 ROWS.

ENDSELECT.

Regards,

Padmam.

Former Member
0 Kudos
256

Hi,

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

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

Reward points if it is helpful...

Regards,

Omakr.

Former Member
0 Kudos
256

select single - when you have the full key in the where clause.

select upto 1 rows - when you don't have the full key.

Regards,

Atish

Former Member
0 Kudos
256

HI

Select single will select only one record and when u know complete key better to use select single.

select upto will select multiple records from DB.

u should write " into table' statment in select staement/

regards

suresh.d

Message was edited by:

suresh dameruppula

Former Member
0 Kudos
256

When you say SELECT SINGLE, it means that you are expecting only one row to be present in the database for the condition you're going to specify in the WHERE clause. so that means, you will have to specify the primary key in your WHERE clause. Otherwise you get a warning.

SELECT UP TO 1 ROWS is used in cases where you just want to make sure that there is at least one entry in the database table which satisfies your WHERE clause. Generally, it is meant to be used for existence-check.

You may not want to really use the values returned by the SELECT statement in this case (thought this may not necessarily be so).And in each case the database optimizer may choose a different strategy to retrieve the data.

Knowing when to use SELECT SINGLE or SELECT ... UP TO 1 ROWS

A lot of people use the SELECT SINGLE statement to check for the existence of a value in a database. 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

SELECT SINGLE field INTO w_field FROM table.

and

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 memory 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, applies any aggregate, ordering or grouping functions to them and then returns the first record of the result set.

Also have a look at:

regards,

Ruchika

reward if useful..............

Former Member
0 Kudos
256

Hi,

When you say SELECT SINGLE, it means that you are expecting only one row to be present in the database for the condition you're going to specify in the WHERE clause. so that means, you will have to specify the primary key in your WHERE clause. Otherwise you get a warning.

SELECT UP TO 1 ROWS is used in cases where you just want to make sure that there is at least one entry in the database table which satisfies your WHERE clause. Generally, it is meant to be used for existence-check.

You may not want to really use the values returned by the SELECT statement in this case (thought this may not necessarily be so).And in each case the database optimizer may choose a different strategy to retrieve the data.

Knowing when to use SELECT SINGLE or SELECT ... UP TO 1 ROWS

A lot of people use the SELECT SINGLE statement to check for the existence of a value in a database. 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

SELECT SINGLE field INTO w_field FROM table.

and

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 memory 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, applies any aggregate, ordering or grouping functions to them and then returns the first record of the result set.

Regards

0 Kudos
256

Hi,

As far as data that is read is concerned you will get only one row.

And in SELECT SINGLE yo have to use a Structure in INTO where has In SELECT UPTO you have to use INTO TABLE.

Regards,

Sesh

Former Member
0 Kudos
256

Hi,

if there exists at least one row of a database

table or view with a certain condition, use the Select ... Up To 1

Rows statement instead of a Select-Endselect-loop with an Exit.

If all primary key fields are supplied in the Where condition you

can even use Select Single.

Select Single requires one communication with the database system,

whereas Select-Endselect needs two.

Regards

Gaurav

Former Member
0 Kudos
256

thanks for the responses