• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 172
  • Last Modified:

SQL joining

Hi,

the structures of the tables as follows.

tblIN        tblOut    tblProf
CardNo    CardNo    ID
...           Picked    Name

I wanto select all records from the two tables for the following criteria.

lblIN.CardNo = tblOut.CardNo
tblOut.Picked= tblProf.ID

can anyone pls. help me with sql statements?


ayha

0
ayha1999
Asked:
ayha1999
  • 2
2 Solutions
 
softplusCommented:
The simplest will work :)
select * from tblIn, tblOut, tblProf where lblIN.CardNo = tblOut.CardNo and tblOut.Picked= tblProf.ID
but more modern are syntaxes with JOIN, but if you have problems figuring it out, try the simple style like above; the server will generally optimize the query to the same net effect.
0
 
david_chiuCommented:
Hi, ayha,

Here is SQL statement for your review, hope it will help!


select i.CardNo, O.Picked, PP.Name
from tblIn I, tblOut O, tblProf PP
Where      I.CardNo = O.CardNo AND O.Picked= PP.ID

Best Regards,
David
0
 
david_chiuCommented:
Hi, ayha,

Please ignore my last answer. I'm late. I'm sorry to Softplus, because you are the first one!!


Best Regards,
David
0
 
ayha1999Author Commented:
Hi,

None of the answers worked. I think my question was not clear.
I will explain:
Suppose I have the following data in tblProf table;

tblProf
ID    Name
1     ABC

Pick are related to ID field of Prof.

I want to retrive all records from tblIn and tbnOut and ...

suppose Pick=1 then I want retrieve Names from Prof table for ID equal to 1.

tblProf
ID  Name
1   Abc


I don't want to use WHERE in query because sometimes my query will look like:

select * from tblIn,tblOut,tblProf Where CardNo = ' txtCardNo ' Or
select * from tblIn,tblOut,tblProf Where Pick= ' txtPick 'etc.

ayha
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now