dbTalk Databases Forums  

SQL Query

comp.databases.postgresql.general comp.databases.postgresql.general


Discuss SQL Query in the comp.databases.postgresql.general forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Jenny
 
Posts: n/a

Default SQL Query - 01-19-2005 , 01:21 PM






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








Reply With Quote
  #2  
Old   
Nikolay A Mirin
 
Posts: n/a

Default Re: SQL Query - 01-19-2005 , 11:40 PM






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 (AT) nospam (DOT) com> wrote

Quote:
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









Reply With Quote
  #3  
Old   
Jenny
 
Posts: n/a

Default Re: SQL Query - 01-21-2005 , 10:52 AM



thank you for the assist.
jenny

"Jenny" <jenny (AT) nospam (DOT) com> wrote

Quote:
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










Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.