By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,652 Members | 1,905 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,652 IT Pros & Developers. It's quick & easy.

SQL Query

P: n/a
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



Nov 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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" <je***@nospam.com> wrote in message
news:gy**************@fe10.lga...
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



Nov 23 '05 #2

P: n/a
thank you for the assist.
jenny

"Jenny" <je***@nospam.com> wrote in message
news:gy**************@fe10.lga...
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


Nov 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.