Connecting Tech Pros Worldwide Help | Site Map

SQL Query

  #1  
Old November 23rd, 2005, 03:03 AM
Jenny
Guest
 
Posts: 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







  #2  
Old November 23rd, 2005, 03:03 AM
Nikolay A Mirin
Guest
 
Posts: n/a

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]

  #3  
Old November 23rd, 2005, 03:03 AM
Jenny
Guest
 
Posts: n/a

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 Threads
Thread Thread Starter Forum Replies Last Post
SQL query help AdrianG answers 5 April 4th, 2007 11:05 PM
SQL Query to VBA Syntax p answers 8 December 5th, 2006 01:25 AM
SQL Query Help schoultzy answers 2 May 19th, 2006 10:45 PM
Simple CrystalReport Chart using SQL Query? Don Wash answers 2 November 18th, 2005 03:24 PM
Oracle SQL query by date vnl answers 7 July 19th, 2005 11:09 PM