Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > Union All & Group By

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-18-03, 09:15
Rosenhan Rosenhan is offline
Registered User
 
Join Date: Feb 2003
Posts: 10
Union All & Group By

I am embarrassed to post this, it seems so simple.

I have read the archives and the solutions do not seem to work with my code. My programing does not recognize the suggested commands.

I am using Access2K and FrontPage2K. Hey, don't laugh.

Here is the code:

SELECT Parking
FROM Bus
WHERE BusNumber=::BusNumber::
UNION ALL
SELECT Parking2
From Parking1

The second SELECT results need to ASC alphabetically.

Of course, GROUP BY applies itself to the whole query, which will not work for me.

I tried to apply the solutions I found in the archives but either FrontPage or Access will not recognize the syntax.

Thanks for any help.

Rosenhan
Reply With Quote
  #2 (permalink)  
Old 04-18-03, 09:31
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 13,558
actually, it's the other way around

each subselect can have its own GROUP BY, but the overall UNION query can have only one ORDER BY

does that help your situation?


rudy
http://r937.com/
Reply With Quote
  #3 (permalink)  
Old 04-18-03, 09:51
Rosenhan Rosenhan is offline
Registered User
 
Join Date: Feb 2003
Posts: 10
I appologize for wasting everyone's time. In my haste I have made the wrong post. THe post should have been:

UNION ALL ORDER BY

The problem is in the ORDER, Not GROUP

SELECT Parking
FROM Bus
WHERE Bus.BusNumber=::BusNumber::
UNION ALL
SELECT Parking2
From Parking1

In this query, ORDER BY can only be applied at the end, and will ORDER the entire query.

I only want to ORDER the second SELECT.

Thanks

Rosenhan
Reply With Quote
  #4 (permalink)  
Old 04-18-03, 10:08
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 13,558
try this --

SELECT Parking
FROM Bus
WHERE Bus.BusNumber=::BusNumber::
UNION ALL
SELECT *
from ( select Parking2 From Parking1 order by parking2 )

or perhaps something like this

SELECT 1 as sortkey1
, ' ' as sortkey2
, Parking
FROM Bus
WHERE BusNumber=::BusNumber::
UNION ALL
SELECT 2 as sortkey1
, Parking2 as sortkey2
, Parking2
From Parking1
order by sortkey1, sortkey2


rudy
Reply With Quote
  #5 (permalink)  
Old 04-18-03, 12:43
Rosenhan Rosenhan is offline
Registered User
 
Join Date: Feb 2003
Posts: 10
Rudy,

Your second example works correctly. The first, I knew from experience, would not work.

I tried previously to apply my own version of your number 2 example, but could not get the syntax accepted. Yours works fine.

Thank you very much.

Rosenhan
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On