I’m no SQL guru, by any means, and I’m having a hard time wrapping my head around how to do a certain SQL query.
I have three Oracle database tables, MBRHISTDETL, LOCINFODETL, and METERCHGDETL. From MBRHISTDETL I’ll get the following fields: MBRSEP, LOCATION, BILLTYPE, BILLMOYR, KWH. From LOCINFODETL (LOCATION is key) I’ll get DIST, CYCLE, ADDR1. From METERCHGDETL (MBRSEP is key) I’ll get METER.
So far, using my query below, I’m able to get all the information I need from MBRHISTDETL and LOCINFODETL. However, I don’t quite now how to add the next table, METERCHRDETL, into the query statement. Can someone help me out with this?
Here’s my query, so far:
SELECT LOCINFODETL.LOCATION AS L.LOCATION,
LOCINFODETL.DIST, LOCINFODETL.CYCLE,
LOCINFODETL.ADDR1, MBRHISTDETL.MBRSEP,
MBRHISTDETL.LOCATION AS M.LOCATION,
MBRHISTDETL.BILLTYPE, MBRHISTDETL.BILLMOYR,
MBRHISTDETL.KWH
FROM MBRHISTDETL
INNER JOIN L.LOCINFODETL ON H.MBRHISTDETL.LOCATION = L.LOCATION
WHERE MBRHISTDETL.BILLTYPE = '09'
AND CAV_MBRHISTDETL.BILLMOYR <> '9999'
AND SUBSTR(LOCINFODETL.CYCLE,0,2) = '04'
AND LOCINFODETL.DIST = '16'
This should get you started — but you need to know which field links your M table.
Also — just a style tip — if you’re trying to make sense out of sql for the first time especially — you’ll be able to proof your sql a lot easier if you format it a little more vertcially. My style might not be the best, but you can see if it makes things easier to read for you anyway.