complex query challenge

complex query challenge

am 25.01.2008 19:28:02 von darwinbaldrich

Hello everybody,


I'd like to be guide to do that:

I have 2 tables [In Access 2002]:

---------------- ----------------
| Table_1 | | Table_2 |
---------------- ----------------
| DIV | ST | | SID | DIV |

I need to make a query to retrieve 2 columns:
The first one will display absolutly all the pd's from
(SELECT pd FROM Table_1 WHERE St = 'AV')
The second one will show (null or not null values) from
(SELECT div FROM Table_2 WHERE sid = 'T26')
I want to know what DIV's from the Table_1 are used in the Table_2.
Something like this:

| DIV |Exist|
200 X
300
400
500 X
600

Thanks

Re: complex query challenge

am 25.01.2008 23:02:43 von MGFoster

CenturionX wrote:
> Hello everybody,
>
>
> I'd like to be guide to do that:
>
> I have 2 tables [In Access 2002]:
>
> ---------------- ----------------
> | Table_1 | | Table_2 |
> ---------------- ----------------
> | DIV | ST | | SID | DIV |
>
> I need to make a query to retrieve 2 columns:
> The first one will display absolutly all the pd's from
> (SELECT pd FROM Table_1 WHERE St = 'AV')
> The second one will show (null or not null values) from
> (SELECT div FROM Table_2 WHERE sid = 'T26')
> I want to know what DIV's from the Table_1 are used in the Table_2.
> Something like this:
>
> | DIV |Exist|
> 200 X
> 300
> 400
> 500 X
> 600
>
> Thanks

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Not sure what you want since you give 3 examples of possible solutions.


What DIVs from T1 are used in T2:

SELECT T2.Div
FROM Table_2 As T2 INNER JOIN Table_1 As T1 ON T2.div=T1.div

--
MGFoster:::mgf00 earthlink net
Oakland, CA (USA)
** Respond only to this newsgroup. I DO NOT respond to emails **

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBR5pcfoechKqOuFEgEQJ0iQCg4gTmZwSp6JqB+h8e9qXYkRguBSgA n0aL
WLSgkld3QGLwI/jgyoudqiFl
=puZ/
-----END PGP SIGNATURE-----

Re: complex query challenge

am 26.01.2008 07:54:23 von Nojoke

Try.

SELECT Table_1.DIV, IIf([Table_2].[DIV],"X") AS Exist
FROM Table_1 LEFT JOIN Table_2 ON Table_1.DIV = Table_2.DIV;

Jørn

"CenturionX" skrev i en meddelelse
news:c985b4bf-dcde-42a1-b4fe-3af222e745f4@v46g2000hsv.google groups.com...
> Hello everybody,
>
>
> I'd like to be guide to do that:
>
> I have 2 tables [In Access 2002]:
>
> ---------------- ----------------
> | Table_1 | | Table_2 |
> ---------------- ----------------
> | DIV | ST | | SID | DIV |
>
> I need to make a query to retrieve 2 columns:
> The first one will display absolutly all the pd's from
> (SELECT pd FROM Table_1 WHERE St = 'AV')
> The second one will show (null or not null values) from
> (SELECT div FROM Table_2 WHERE sid = 'T26')
> I want to know what DIV's from the Table_1 are used in the Table_2.
> Something like this:
>
> | DIV |Exist|
> 200 X
> 300
> 400
> 500 X
> 600
>
> Thanks