Wrox Home  
Search P2P Archive for: Go

  Return to Index  

sql_language thread: Select Into?


Message #1 by "Hugh McLaughlin" <hugh@k...> on Sat, 22 Feb 2003 16:35:35
Have you also verified for the record that has the 'Y' that there is an
entry in tblEmployees?  Try a "left outer join" like this and see if the
results change:
Select tblEmployeeTime.SocialSecurity, tblEmployees.FirstName, 
tblEmployees.LastName From tblEmployeeTime left outer Join tblEmployees On 
tblEmployeeTime.SocialSecurity=tblEmployees.SocialSecurity WHERE 
tblEmployeeTime.LoggedIn = 'Y'

If you get results back then you were missing the entry in tblEmployees for
the person logged in.

Brian freeman

-----Original Message-----
From: Hugh McLaughlin [mailto:hugh@k...]
Sent: Saturday, February 22, 2003 3:28 PM
To: sql language
Subject: [sql_language] RE: Select Into?


Again, thanks for the help.  Here is what I tried:

Select tblEmployeeTime.SocialSecurity, tblEmployees.FirstName, 
tblEmployees.LastName From tblEmployeeTime Inner Join tblEmployees On 
tblEmployeeTime.SocialSecurity=tblEmployees.SocialSecurity WHERE 
tblEmployeeTime.LoggedIn = 'Y'

What I am trying to do is find all the Social Security numbers in tbl 
EmployeeTime that have a logged in of 'Y', the return the corresponding 
name for the Social Security number, this being found in tblEmployees.  
When I ran this query, it returned no records, but I have verified that 
there is one record that has a LoggedIn value of'Y'.


> All you need to do is use the joined query with you condition:
select table1.socialsecurity,table2.name form table1 inner join table2 on
table1.socialsecurity=table2.socialsecurity
where table1.loggedin='Y'

That should do it.

Brian

-----Original Message-----
From: Hugh McLaughlin [mailto:hugh@k...]
Sent: Saturday, February 22, 2003 1:29 PM
To: sql language
Subject: [sql_language] RE: Select Into?


I don't think these will work quite right because part of the actual 
query needs to be 

Select SocialSecurity From Table1 WHERE LoggedIn='Y'

This part of the query then returns the SocialSecurity that needs to then 
be looked up in the other table to return the first and last name.

> Hugh,

Try this:

select tn.name, ts.socsec from table_name tn 
/*table_name is the name of the table where the names are stored.
table_socialsecurity is the name of the table where the social security 
#'s
are stored.*/
join table_socialsecurity ts
on tn.socsec=ts.socsec
where tn.name = 'First Last' --where First and Last is the name you are
querying.

I hope this helps.

-----Original Message-----
From: Hugh McLaughlin [mailto:hugh@k...] 
Sent: Saturday, February 22, 2003 4:36 PM
To: sql language
Subject: [sql_language] Select Into?


Hello Everyone and thanks for your help in advance.  I need to develop a 
query the looks up a Social Security number from one table, then takes 
that Social Security number and queries a second table to return the 
corresponding name.  However, I am relatively new to compund queries and 
am not sure how to do this.  I think it would involve a Select Into, but 
I am not sure.  Any ehlp would be greatly appreciated.  Thank.s





  Return to Index