If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > UNION Query Question

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-27-03, 09:27
RRepsher RRepsher is offline
Registered User
 
Join Date: Aug 2002
Posts: 23
UNION Query Question

I have some list boxes that I use in a QBF form. I need the list to look like:

!All
John Smith
Michael McGee
Robert James
etc...

The query below only returns the first 4 characters of the user name (the length of "!ALL")

!All
John
Mich
Robe

Is this typical? I tried to find something about it in the manual...

Thanks,

Rick

SELECT DISTINCT "!All" AS Name, 0 AS UserID FROM tblUser;
UNION SELECT CONCAT(tblUser.FirstName, " ", tblUser.LastName) AS Name, tblUser.UserID
FROM tblUser
ORDER BY Name;
__________________
A good cook doesn't use a smoke alarm for a timer.
Reply With Quote
  #2 (permalink)  
Old 10-27-03, 13:20
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
yes, it is most typical

the datatype specs for the result set are taken from the first query in the union

just reverse the order --
Code:
SELECT CONCAT_WS(' ',tblUser.FirstName, tblUser.LastName) AS Name
     , tblUser.UserID 
  FROM tblUser
UNION ALL
SELECT DISTINCT '!All'
     , 0 
  FROM tblUser
ORDER BY Name
note: use CONCAT_WS so that you don't get a leading space when the first name is null

use UNION ALL to avoid a complete sort of the result set looking for duplicate rows (because there can't be any)

rudy
http://r937.com/
Reply With Quote
  #3 (permalink)  
Old 10-27-03, 13:21
RRepsher RRepsher is offline
Registered User
 
Join Date: Aug 2002
Posts: 23
Thanks for the reply... I didn't think about reversing the order.
__________________
A good cook doesn't use a smoke alarm for a timer.
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

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