combine two sql queries - see example

thydzik

Registered User.
Local time
Today, 20:05
Joined
Jun 17, 2006
Messages
27
I have the following two queries

Query1:
Code:
SELECT TAGS.ID, ALARMS.*
FROM TAGS RIGHT JOIN ALARMS ON TAGS.NAME1=ALARMS.NAME1;

Query2:
Code:
SELECT SUBGROUPS.*, Query1.*
FROM SUBGROUPS LEFT JOIN Query1 ON SUBGROUPS.ID=Query1.ID;


How do I combine these to make one?
 
bump.

I thought this problem what be fairly straight forward to answer. basically how do I embed two sql queries together...
 
Im still a bit of a novice at SQL but would this work:

SELECT SUBGROUPS.*, TAGS.ID, ALARMS.*

FROM SUBGROUPS,
(
SELECT TAGS.ID, ALARMS.*
FROM TAGS RIGHT JOIN ALARMS ON TAGS.NAME1=ALARMS.NAME1;
) AS QUERY1

LEFT JOIN QUERY1 ON SUBGROUPS.ID=QUERY1.ID
 
thanks for the reply, i tried your code and it didn't seam to work, I then tried to modify it and try a lot of different things, and still couldn't make it work.

Code:
SELECT SUBGROUPS.*, (SELECT TAGS.ID, ALARMS.* FROM TAGS RIGHT JOIN ALARMS ON TAGS.NAME1=ALARMS.NAME1;) AS QUERY1temp
FROM SUBGROUPS LEFT JOIN QUERY1temp ON SUBGROUPS.ID=QUERY1temp.ID;

i thought this would work, but get the error can not find QUERY1temp.

any have any ideas, doesn't have to be correct, just give me soemthing new to try.
 
WORKED IT OUT!

Code:
SELECT SUBGROUPS.*, combined.*
FROM SUBGROUPS LEFT JOIN [SELECT TAGS.ID, ALARMS.* FROM TAGS RIGHT JOIN ALARMS ON TAGS.NAME1=ALARMS.NAME1]. AS combined ON SUBGROUPS.ID=combined.ID;

thanks to this link
SQL - subqueries and "parallel left joins"
 

Users who are viewing this thread

Back
Top Bottom