473,472 Members | 2,174 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

sorting table

Hi friends,
ID LASTNAME
--------+----------------------------
2 FFF
1 XXX
0 CCC
1 DDD
2 BBB
0 EEE
0 GGG
3 III
3 HHH
4 ZZZ
4 ZZZ
please help me in sorting this table. the table should be sorted based
on LASTNAME, and then the ID (only non-zero id should be sorted).
ID LASTNAME
--------+----------------------------
2 BBB
2 FFF
0 CCC
1 DDD
1 XXX
0 EEE
0 GGG
3 HHH
3 III
4 XYZ
4 ZZZ

should be sorted based on last name and should be grouped with the
same ID, except for the ID as 0

May 15 '07 #1
2 1605
Please don't multipost, rather crosspost. Replied in
microsoft.public.sqlserver.server:

SELECT F.ID,
F.LASTNAME
FROM Foobar AS F
LEFT OUTER JOIN
(
SELECT ID,
MIN(LASTNAME) AS GRP
FROM Foobar
WHERE ID 0
GROUP BY ID
) AS G
ON F.ID = G.ID
ORDER BY COALESCE(G.GRP, F.LASTNAME),
F.ID,
F.LASTNAME

HTH,

Plamen Ratchev
http://www.SQLStudio.com

May 15 '07 #2
Hi Plamen,
It was really great.Thanks for your immediate reply.

Regards,
Arunkumar.Dharuman

On May 15, 5:54 pm, "Plamen Ratchev" <Pla...@SQLStudio.comwrote:
Please don't multipost, rather crosspost. Replied in
microsoft.public.sqlserver.server:

SELECT F.ID,
F.LASTNAME
FROM Foobar AS F
LEFT OUTER JOIN
(
SELECT ID,
MIN(LASTNAME) AS GRP
FROM Foobar
WHERE ID 0
GROUP BY ID
) AS G
ON F.ID = G.ID
ORDER BY COALESCE(G.GRP, F.LASTNAME),
F.ID,
F.LASTNAME

HTH,

Plamen Ratchevhttp://www.SQLStudio.com

May 15 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: pmud | last post by:
Hi, I am using teh following code for sorting the data grid but it doesnt work. I have set the auto generate columns to false. & set the sort expression for each field as the anme of that...
4
by: Gareth Gale | last post by:
I'm trying to implement a way of allowing a user to sort a HTML table via Javascript on the client. I've seen lots of samples where single column sorting (asc or desc) is shown, but I'd like nested...
4
by: suzy | last post by:
hello. how can i sort data in a dataset? all the examples i have seen on msdn, etc are sorting a dataview. this works fine, but i want to return the results in xml and the dataview doesn't...
7
by: Kamal | last post by:
Hello all, I have a very simple html table with collapsible rows and sorting capabilities. The collapsible row is hidden with css rule (display:none). When one clicks in the left of the...
1
by: jjjoic | last post by:
Hi, I use Access 2003 to generate the back-end data for a ColdFusion report at work. The report is sorted by a column and based on the sorting, rankings are assigned to each row(i.e. the biggest...
2
by: cluce | last post by:
i have a table sorting feature on my website that works everywhere else except in firefox. but the example code does work in firefox. this has me stumped. The problem is the links in the table...
2
by: Bob Laubla | last post by:
Hello I have a very complex maketable query with many records and involving multiple VB functions which call other functions. I need this table to be sorted by the first field. But no matter what...
6
by: =?Utf-8?B?RGFu?= | last post by:
I am reposting a question from about 3 weeks ago ("sorting capability"). I have an aspx page in which I get the data from a database dynamically, through C# code, by creating a dynamic table...
3
by: nagmvs | last post by:
Hi to all I have one table with 6 columns and 20 rows.I want to sort each and every column when i click the column name in the table. for sorting i create one more page.when i click the column...
5
by: jrod11 | last post by:
hi, I found a jquery html table sorting code i have implemented. I am trying to figure out how to edit how many colums there are, but every time i remove code that I think controls how many colums...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.