Solved

sql query help

Posted on 2009-06-30
2
338 Views
Last Modified: 2013-12-07
I have two tables to keep it simple they are ORDERS and ZONES, i have two parameters to pass to the query OrderRef and Zone, so if i have OrderRef = '123' and Zone = 'ONE' i only want results back from ORDERS table where BIN is in ZONE ONE,

ORDERS

OrderRef      Product      Bin      VALUE
123      ABC1      A      9.99
123      ABC2      B      12.99
123      ABC3      H      15.99
123      ABC4      C      4.99
123      ABC5      S      6.99

ZONES

ZONE      BINFROM      BINTO
ONE      A      C
TWO      D      J
THREE      K      Z

Desired Result is for OrderRef ='123' and Zone='ONE' is

OrderRef      Product      Bin      VALUE
123      ABC1      A      9.99
123      ABC2      B      12.99
123      ABC4      C      4.99

Result if OrderRef='123' and Zone='TWO' is
OrderRef      Product      Bin      VALUE
123      ABC3      H      15.99

I could do this with two queries but would like to build it into one,  
0
Comment
Question by:IanPaskin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 25

Accepted Solution

by:
lwadwell earned 500 total points
ID: 24750030
Hi IanPaskin,

you could try something like ...

SELECT t2.OrderRef, t2.Product, t2.Bin, t2.VALUE
FROM zones t1
JOIN orders t2
ON t2.bin between t1.binfrom and t1.binto AND t2.orderref = '123'
WHERE t1.zone = 'ONE'

lwadwell
0
 
LVL 14

Expert Comment

by:shru_0409
ID: 24752041
select o.OrderRef,o.Product,o.Bin,o.VALUE
from orders o, ZONES z
where ascii(O.BIN) between ascii(z.BINFROM) and ascii(z.BINTO)
and z.zone = 'ONE'

this could help u
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.
Suggested Courses

626 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