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