Connecting Tech Pros Worldwide Forums | Help | Site Map

SQL Query

Jenny
Guest
 
Posts: n/a
#1: Nov 23 '05
hi, could someone please tell me how do I get a query to show the (*) fields
in table2 only when table2.field1 exist in table1.field1

thanks in advance.
jenny


table 1 contains
--------------------------
field1
1
5
4
9


table 2 contains
--------------------------------

field1 field2
1 a
1 b
1 j
1 m
2 a
2 b
3 a
3 n
4 c
4 d


--------------
desired results:
---------------

table2.field1 table2.field2
1 a
1 b
1 j
1 m
4 c
4 d










Nikolay A Mirin
Guest
 
Posts: n/a
#2: Nov 23 '05

re: SQL Query


Assuiming the records t2 do not duplicate

SELECT DISTINCT t2.*
FROM table2 t2 LEFT JOIN table1 t1 ON (t1.field1=t2.field1);


Also, check out EXISTS,
http://www.postgresql.org/docs/7.4/i....html#AEN12473


RTFM, RTFM!!!!!


"Jenny" <jenny@nospam.com> wrote in message
news:gyyHd.653$MH.621@fe10.lga...[color=blue]
> hi, could someone please tell me how do I get a query to show the (*)
> fields
> in table2 only when table2.field1 exist in table1.field1
>
> thanks in advance.
> jenny
>
>
> table 1 contains
> --------------------------
> field1
> 1
> 5
> 4
> 9
>
>
> table 2 contains
> --------------------------------
>
> field1 field2
> 1 a
> 1 b
> 1 j
> 1 m
> 2 a
> 2 b
> 3 a
> 3 n
> 4 c
> 4 d
>
>
> --------------
> desired results:
> ---------------
>
> table2.field1 table2.field2
> 1 a
> 1 b
> 1 j
> 1 m
> 4 c
> 4 d
>
>
>
>
>
>
>[/color]

Jenny
Guest
 
Posts: n/a
#3: Nov 23 '05

re: SQL Query


thank you for the assist.
jenny

"Jenny" <jenny@nospam.com> wrote in message
news:gyyHd.653$MH.621@fe10.lga...[color=blue]
> hi, could someone please tell me how do I get a query to show the (*)[/color]
fields[color=blue]
> in table2 only when table2.field1 exist in table1.field1
>
> thanks in advance.
> jenny
>
>
> table 1 contains
> --------------------------
> field1
> 1
> 5
> 4
> 9
>
>
> table 2 contains
> --------------------------------
>
> field1 field2
> 1 a
> 1 b
> 1 j
> 1 m
> 2 a
> 2 b
> 3 a
> 3 n
> 4 c
> 4 d
>
>
> --------------
> desired results:
> ---------------
>
> table2.field1 table2.field2
> 1 a
> 1 b
> 1 j
> 1 m
> 4 c
> 4 d
>
>
>
>
>
>
>[/color]


Closed Thread


Similar PostgreSQL Database bytes