need help writing query

  • Thread starter Thread starter absoft
  • Start date Start date
A

absoft

I have a mapping table that I need to query to generate my report. The
table structure is as below:

Mapping table
m_id m_table m_dept org dept id table
1 1 1 1 2 1 2
1 1 1 1 2 2 3
1 1 1 1 3 1 1

Corresponding to tables 1, 2 and 3 I have tables t1, t2 and t3 with the
following structure
table t1
org dept id desc
1 1 1 table 1 dept 1
1 2 2 table 1 dept 2

Quering the mapping table:
Select * from Mapping where m_id = 1 and m_table=1 and m_dept = 1
returns 3 rows as above.

Now I need to write a query that would use the above query result and
display records from tables t1, t2 or t3 based on above mapping where
the org, dept and id is equal to that in mapping table.
e.g.
above query should return something like this:

org dept id desc
1 2 1 table 2 dept 2
1 2 2 table 3 dept 2
1 3 1 table 1 dept 3
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top