devxlogo

A Simple Sort Not Working

A Simple Sort Not Working

Question:
I have the following:

sql="select * from products"

How do I sort or order by two columns retrieved in the “*”?

Answer:
You need to specify them directly in a clause following the one you have, as in:

select * from authorsorder by au_lname,au_fname

This will get you all the columns in authors sorted by last name, then first name.

Note that it is poor practice to use “select *” because you could be opening a Pandora’s box of unexpected results. It is better practice to name the columns you expect in the result set or use the INFORMATION_SCHEMA views to find out what you need.

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist