Application Development and Automation 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: 
Read only

Using order by in the select query

Former Member
0 Likes
839

Hi All,

I have query in which I need the latest record. To get the latest record, I can

1) Select all entries into an internal table and sort them descending and get the first one

2) Select all entries into an internal table and order by in the select statement itself.

Then read the first one.

Which approach should be better as for as the performance is concern.

The query is on MKPF table and I have the material document number. I need the latest entry.

Regards,

Shahu

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
800

ORDER BY is obsolete.

The second approach is better when if you need maximum for each documnt.

you can directly use the

select max * if you need only the maximum of all.

Regards,

Ravi

Hi All,

I have query in which I need the latest record. To get the latest record, I can

1) Select all entries into an internal table and sort them descending and get the first one

2) Select all entries into an internal table and order by in the select statement itself.

Then read the first one.

Which approach should be better as for as the performance is concern.

The query is on MKPF table and I have the material document number. I need the latest entry.

Regards,

Shahu

5 REPLIES 5
Read only

Former Member
0 Likes
800

Hi

Try SELECT MAX(datum) ... command

Anyways your first option seems fine. Its not the fastest solution, but surely will work.

Regrds

Tamá

Read only

Former Member
0 Likes
800

first one because order by in select make your performance decrease.

regards

shiba dutta

Read only

Former Member
0 Likes
801

ORDER BY is obsolete.

The second approach is better when if you need maximum for each documnt.

you can directly use the

select max * if you need only the maximum of all.

Regards,

Ravi

Read only

Former Member
0 Likes
800

Hi,

The first one would be better.At the most we should not use order by in select statement bcoz it directly sorts the data according to that in database itself reverting performance issues.

Otherwise you can use select max* if records are less.

Reward points if helpful.

Thanks,

Ponraj.s.

Read only

Former Member
0 Likes
800

Thank you all...

Regards,

Shahu