469,148 Members | 1,278 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,148 developers. It's quick & easy.

UNIONS in subqueries

Hello!

I have a problem using UNIONs inside subqueries. I have simplified my
query to make it more readable. The question is about the right syntax.
1.
This works fine /UNION/

(SELECT f15.Form15SampleTube1RnaBarcode AS ObjectId,
f15.Form15PatientID AS PtId FROM form15 f15
WHERE f15.Form15SampleTube1RnaBarcode IN ('01D2V','01DH6'))

UNION

(SELECT f15.Form15SampleTube6RnaBarcode AS ObjectId,
f15.Form15PatientID AS PtId FROM form15 f15
WHERE f15.Form15SampleTube6RnaBarcode IN ('01D2V','01DH6'))
2.
This works fine too /subquery/:

SELECT ObjectId FROM

(SELECT f15.Form15SampleTube1RnaBarcode AS ObjectId,
f15.Form15PatientID AS PtId FROM form15 f15
WHERE f15.Form15SampleTube1RnaBarcode IN ('01D2V','01DH6')) AS
SubTable1;
3.
But when I run 1&2 mixed I get in troubles. This is a query draft,
can't come up with the right syntax:
SELECT ObjectId FROM
(SELECT f15.Form15SampleTube1RnaBarcode AS ObjectId,
f15.Form15PatientID AS PtId FROM form15 f15
WHERE f15.Form15SampleTube1RnaBarcode IN ('01D2V','01DH6'))

UNION

(SELECT f15.Form15SampleTube6RnaBarcode AS ObjectId,
f15.Form15PatientID AS PtId FROM form15 f15
WHERE f15.Form15SampleTube6RnaBarcode IN ('01D2V','01DH6'))
I tried many combinations and got various syntax errors. Any ideas?
Thanks,
Luke

May 23 '06 #1
2 5750
Luke wrote:
SELECT ObjectId FROM
(SELECT f15.Form15SampleTube1RnaBarcode AS ObjectId,
f15.Form15PatientID AS PtId FROM form15 f15
WHERE f15.Form15SampleTube1RnaBarcode IN ('01D2V','01DH6'))

UNION

(SELECT f15.Form15SampleTube6RnaBarcode AS ObjectId,
f15.Form15PatientID AS PtId FROM form15 f15
WHERE f15.Form15SampleTube6RnaBarcode IN ('01D2V','01DH6'))


Try this:

SELECT FROM
(
(SELECT ...)
UNION
(SELECT ...)
)

That is, put another pair of parens around the whole UNION query.

Regards,
Bill K.
May 24 '06 #2
Hi, thanks. I think I tried same as yours /no access now/ and ended up
with syntax errors.
But this solution works (got it from a guy from mysql.lists):

SELECT FROM

(SELECT FROM...

UNION

SELECT FROM... ) as abc

Regards,
Luke

May 25 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Daniel Elliott | last post: by
6 posts views Thread by Neil Zanella | last post: by
4 posts views Thread by uralmutlu | last post: by
67 posts views Thread by bluejack | last post: by
debasisdas
reply views Thread by debasisdas | last post: by
11 posts views Thread by pereges | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.