473,728 Members | 2,103 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Form15Sampl eTube1RnaBarcod e AS ObjectId,
f15.Form15Patie ntID AS PtId FROM form15 f15
WHERE f15.Form15Sampl eTube1RnaBarcod e IN ('01D2V','01DH6 '))

UNION

(SELECT f15.Form15Sampl eTube6RnaBarcod e AS ObjectId,
f15.Form15Patie ntID AS PtId FROM form15 f15
WHERE f15.Form15Sampl eTube6RnaBarcod e IN ('01D2V','01DH6 '))
2.
This works fine too /subquery/:

SELECT ObjectId FROM

(SELECT f15.Form15Sampl eTube1RnaBarcod e AS ObjectId,
f15.Form15Patie ntID AS PtId FROM form15 f15
WHERE f15.Form15Sampl eTube1RnaBarcod e 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.Form15Sampl eTube1RnaBarcod e AS ObjectId,
f15.Form15Patie ntID AS PtId FROM form15 f15
WHERE f15.Form15Sampl eTube1RnaBarcod e IN ('01D2V','01DH6 '))

UNION

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

May 23 '06 #1
2 6132
Luke wrote:
SELECT ObjectId FROM
(SELECT f15.Form15Sampl eTube1RnaBarcod e AS ObjectId,
f15.Form15Patie ntID AS PtId FROM form15 f15
WHERE f15.Form15Sampl eTube1RnaBarcod e IN ('01D2V','01DH6 '))

UNION

(SELECT f15.Form15Sampl eTube6RnaBarcod e AS ObjectId,
f15.Form15Patie ntID AS PtId FROM form15 f15
WHERE f15.Form15Sampl eTube6RnaBarcod e 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2059
by: Daniel Elliott | last post by:
Hello, I was wondering if anyone would be able to help me with a problem I'm having. I'm trying to use the following query: SELECT Distinct c.site_id FROM campsite c WHERE c.site_id NOT IN (SELECT cs.site_id FROM campsite_status cs WHERE c.site_id = cs.site_id
5
2424
by: Nick | last post by:
Im moving a development app (MySQL 5.0) to a different server which runs MySQL 4.0.20-standard. I am getting errors on queries that have subqueries such as... SELECT id FROM table1 WHERE id IN ( SELECT id FROM table1 )
6
13379
by: Neil Zanella | last post by:
Hello, I would like to know whether the following C fragment is legal in standard C and behaves as intended under conforming implementations... union foo { char c; double d; };
23
2827
by: rohit | last post by:
Hi, In my couple of years of experience, I have never found a single instance where I needed to use unions and bitfields(though I have used structures).I was just imagining where would these find relevance.Though both of these(bitfields and unions) are used where space is a constraint(so I can assume always in embedded systems,where memory is particularly less)and we want to save space/memory. As far as I have read, there is no...
4
1764
by: uralmutlu | last post by:
Hi, I was wandering if I can have classes in unions? I basically have source code in a format very similar to: union example { ClassA variable1; ClassB variable2; };
67
3348
by: bluejack | last post by:
A recent post asking for help with unions reminded me of this component of the C language that I have only used a couple of times, and those almost entirely out of personal whim -- Unions for the sake of Unions simply because I wanted to see one in action. Granted: it makes it possible to save a few bytes of storage when you have something that can be a chicken or a rooster, but not both, and you're always going to know which it is. ...
4
2956
by: muzu1232004 | last post by:
Can anyone explain me when we use correlated subqueries rather than nested subqueries. Do all the correlated subqueries can be written in nested subqueries form as well ? What are the major conditions that apply whenever we write a correlated subquery and why we go for it ? Please let me know about this as i am not clear which to use when.
0
5707
debasisdas
by: debasisdas | last post by:
Using Subqueries ================== The sub query is often referred to as a nested SELECT, Sub - SELECT, or inner SELECT statement. The sub query executes once before the main query. The result of the sub query is used by the main query (outer Query). You can place the sub query in a number of SQL clauses. WHERE clause
11
2013
by: pereges | last post by:
Hello, can some one please guide me a little into using unions. I read about unions in K & R but I am finding it difficult to apply to my problem at hand. I want to save up some space by using unions . My questions are : 1. Is it dangerous to use unions ? Is it worth the trouble if I want to save memory ? Are they error prone ? 2. I read that it is not possible to access more than 1 member at any instant from a union. What does this...
0
8911
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8760
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9426
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9280
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9139
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6719
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6015
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3238
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2673
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.