Hi,
I want one query in SQL400, I will give small example?
Suppose there are two tables,
TAb1 Tab2
1.CMP 1.CMP
2.Item NO 2. Item NO
3.Status 3.Warehouse
4.Quantity 4.Costing type
Now I want the data from tab2 where warehouse = 502 , Costing type = '2' and status = '20' (tab1) so, how to write the query? Plz read the two tables.
Software/Hardware used:
yes
ASKED:
April 11, 2012 6:37 AM
UPDATED:
April 20, 2012 7:27 PM
plz try this query for your question.
query:
select aa.status,bb.warehouse,bb.costing from tbl1 aa, tbl bb where bb.warehouse=502 or bb.costing=2 or aa.status=20 and aa.itemno=bb.itemno;
or perhaps the OR’s should be AND’s ?
Charlie we r not Oracle expert thats why asking? I’m not teling to do my homework? I’m just asking my query? bcoz that is necessarry in my work?
So Gowriking gave you a solution.
I provided a useful comment.
You can try this in SQL/400 and see how it works.
Show us what you’ve done and discuss with us what it lacks
and we’ll guide you to greater knowledge and a solved problem.
Phil
Sssss, you don’t need to be an “Expert” at all to build a query for that.
…we r not Oracle expert…
Now it’s becoming confused.
Is this a question about Oracle or SQL/400? Those can be very different. (But both may be just about the same for this specific question.)
Tom
try this
select * from tab2 a, tab1 b
where a.warehouse = 502
and a.Costing type = ’2′
and b.status = ’20′
and a.item no=b.item no
Thanks Phil
Good Pointers Phil and 9783444184
Thanks
I want the data from tab2 where warehouse = 502 , Costing type = ’2′
That part is easy:
…and status = ’20′ (tab1)
But adding that condition can make it more difficult because there are different ways it can be done. One possibility is to add this to the WHERE clause:
If you don’t need the data from the columns in tab1, then there might be no reason to do a JOIN of the two tables. If decent indexes are defined over tab1, a test of EXISTS() may be more efficient.
Tom