tags:

views:

17

answers:

2

can any one help me in generating query for the below scenario?

i have twop tables TableA and TableB

TableA has teh follwing columns EMPLOYEEID, SKILLSETCODE,CERTID, LASTNAME, FIRSTNAME, MIDDLEINITIAL

TableB has two columns EMPLOYEEID and key_user

i want to SELECT EMPLOYEEID, SKILLSETCODE,CERTID, LASTNAME, FIRSTNAME, MIDDLEINITIAL FROM TableA WHERE EMPLOYEEID = (select employeeid from TableB where key_user='249')

how can i generate a sql query for the above scenario?

+1  A: 

Use a join.

SELECT TableA.EMPLOYEEID, SKILLSETCODE,CERTID, LASTNAME, FIRSTNAME, MIDDLEINITIAL 
FROM TableA, TableB
WHERE TableA.EMPLOYEEID = TableB.employeeid 
and TableB.key_user='249'
DVK
If the DBMS supports it, a natural join would be neater (`... FROM TableA NATURAL JOIN TableB WHERE key_user = '249'`)
Chris Smith
@Chris - true, though I tend to do a lot of Sybase stuff so I kind of weigh towards the most portable SQL in my preferences
DVK
A: 

Alternately

SELECT TableA.EMPLOYEEID, SKILLSETCODE,CERTID, LASTNAME, FIRSTNAME, MIDDLEINITIAL 
FROM TableA
  INNER JOIN TableB
    ON TableA.EMPLOYEEID = TableB.employeeid 
WHERE TableB.key_user='249'
wcm