SQL joining

Posted on 2005-05-15
Last Modified: 2010-03-19

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?


Question by:ayha1999
    LVL 13

    Accepted Solution

    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.

    Assisted Solution

    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,

    Expert Comment

    Hi, ayha,

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

    Best Regards,
    LVL 7

    Author Comment


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

    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.

    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.


    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
    This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
    Via a live example, show how to shrink a transaction log file down to a reasonable size.
    Via a live example, show how to setup several different housekeeping processes for a SQL Server.

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now