SQLTeam.com | Weblogs | Forums

Sql ordered query

I am new to SQL and I have been working on some basic queries for a children activity database.

How do I make the output table ordered alphabetically by child surname, with children with the same surname being listed alphabetically with their first name, and for each child in the output, their activity ordered alphabetically by activity name.

Below is the statement i currently have but I am not too sure if this is correct.

SELECT child_fname,child_sname, activity_name,activity_day FROM child,activity ORDER BY child_sname,child_fname,activity_name ASC;

image

image

How will you write this script in SQL.
I understand the logic but how to do you write the MSQL Statement .

The statement you gave looks correct to me; that should give you the ordering you want.

The join doesn't look right - you are creating a cross join so all activity is related to all child rows. You need to relate the child and activity tables on the key value.

Oops, I overlooked the CROSS JOIN part (because of the old non-JOIN syntax, I think).