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: 

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

Former Member
0 Kudos

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

11 REPLIES 11

Former Member
0 Kudos

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

Thanks

Vikranth khimavath

Message was edited by:

Khimavath Vikranth

Message was edited by:

Khimavath Vikranth

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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 .

Former Member
0 Kudos

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

0 Kudos

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.