General discussion

Locked

SQL Query Question

By IT94536 ·
I have two inventory transaction tables. One is a history table, and the other is a current table. What would the SQL look like so that I can get the results from both tables for a specific item number?

Thanks.

This conversation is currently closed to new comments.

3 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

SQL Query Question

by o2 In reply to SQL Query Question

Use 'UNION', like:
SELECT c1, c2,..., cN
FROM current_table
WHERE item_id = your_item_id
UNION
SELECT C1, C2,..., CN
FROM archive_table
WHERE item_id = your_item_id;

Good luck
Oleg

Collapse -

Join?

by bk3004 In reply to SQL Query Question

Clearly this will need a join on both tables. Something on the lines of following.

If its a one time query following is good instead of parameters since it will give a good query plan.

Also see if you have index on ITEM_ID else it might end up table scanning.

select *
from TRAN_HIST A, TRAN_CURRENT B
where A.ITEM_ID='ABCD'
and B.ITEM_ID='ABCD'

Collapse -

wrong forum

by john.a.wills In reply to SQL Query Question

This belongs in Technical Q & A.

Back to Software Forum
3 total posts (Page 1 of 1)  

Related Discussions

Related Forums