Question

I'm trying to do an inner join between 3 tables in an ERD I created. I've successfully built 3 - 3 layer sub-queries using these tables, and when I researched this issue, I can say that in my DDL, I didn't use double quotes so the columns aren't case sensitive. Joins aren't my strong suite so any help would be much appreciated. This is the query im putting in, and the error it's giving me. All of the answers I've seen when people do inner joins they use the syntax, 'INNER JOIN' but I wasn't taught this? Is my method still okay?

SQL> 
SELECT  regional_lot.location, 
        rental_agreement.vin, 
        rental_agreement.contract_ID 
FROM regional_lot, 
     rental_agreement 
WHERE regional_lot.regional_lot_id = vehicle1.regional_lot_ID 
  AND vehicle1.vin = rental_agreement.vin;


                    *
ERROR at line 1:
ORA-00904: "VEHICLE1"."VIN": invalid identifier
Was it helpful?

Solution

For starters, you don't have vehicle1 in your FROM list.

You should give ANSI joins a try. For one, they're a lot more readable and you don't pollute your WHERE clause with join conditions

SELECT regional_lot.location, rental_agreement.vin, rental_agreement.contract_ID
FROM rental_agreement
INNER JOIN vehicle1
    ON rental_agreement.vin = vehicle1.vin
INNER JOIN regional_lot
    ON vehicle1.regional_lot_ID = regional_lot.regional_lot_id;

OTHER TIPS

you foret add table vehicle1 to section "from" in your query:

from regional_lot, rental_agreement, vehicle1

It looks like you have missed to join the table VEHICLE1. Also you can use alias on table names. Try like this,

SELECT regional_lot.location,
       rental_agreement.vin,
       rental_agreement.contr act_ID
FROM   regional_lot a,
       rental_agreement b,
       vehicle1 c
WHERE  a.regional_lot_id = c.regional_lot_ID
AND    c.vin                 = b.vin;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top