Select rows from related or referenced tables in SQL.

  • Hi,

              I m looking for a script or query which shows the rows from related tables against a condition.

    For example we have a table T_Employee. We've to get the all the rows of tables referenced by this table against a condition.                                  i.e. SELECT rows from AllTables where employeeID = 1.

    So that one can the data from all the tables referenced by it based on a condition.

    Thanks in advance,

    Bhupesh  

  • Bhupesh,

    I'm not entirely sure I understand your question. I think what you want is some kind of list of all the tables that have an entry for a particular employee. You could do something like this:

    SELECT 'table1', <table1 primary key>, employeeID
    FROM table1
    where employeeID=1
    UNION
    SELECT 'table2', <table2 primary key>, employeeID
    FROM table2
    where employeeID=1
    UNION
    SELECT 'table3', <table3 primary key>, employeeID
    FROM table3
    where employeeID=1

    etc.

    Steve


    Steve Eckhart

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply