Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Simple SQL query problem

Author  Topic 

dupati1
Posting Yak Master

123 Posts

Posted - 2003-12-15 : 13:54:24
Hi all,

I have the data in the table as shown below:

sex | LastName | FirstName
__________________________
F | Williams | Mary
M | Allan | Wilson
M | Boyd | John
F | Herron | Jamie

Ok now, my query looks as follows

Select * from mytable Order by LastName ASC, Group by sex

What i want to do here is the following:

I want the output to look as follows:

sex | LastName | FirstName
__________________________
F | Herron | Jamie
F | Williams | Mary
M | Allan | Wilson
M | Boyd | John

I mean i want to order by last name with in the sex group.
My query doesnt work. Please help me out.

Thanks in advance.

VJ


tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2003-12-15 : 14:02:33
SELECT sex, LastName, FirstName
FROM myTable
ORDER BY sex, LastName

BTW, your query doesn't even compile.

Tara
Go to Top of Page

dupati1
Posting Yak Master

123 Posts

Posted - 2003-12-15 : 14:04:09
Thanks a lot.

I got it working.

Vj
Go to Top of Page

JimL
SQL Slinging Yak Ranger

1537 Posts

Posted - 2003-12-16 : 08:32:01
F.Y.I.

Stay far far away from using Select *

It is a very bad habit and will cause you alot of grief latter on.

You will notice Tara listed each collumn name, This is the correct way.

Jim
Users <> Logic
Go to Top of Page
   

- Advertisement -