I have the following tables:
CREATE TABLE CUSTOMERS
(customerID INT PRIMARY KEY,
customerFullName VARCHAR(20) NOT NULL);
CREATE TABLE VEHICLES
(vehicleVIN VARCHAR(25) PRIMARY KEY,
vehicleMake VARCHAR(15) NOT NULL);
CREATE TABLE SALES
(saleID INT PRIMARY KEY,
customerID INT,
vehicleVIN VARCHAR(25));
CONSTRAINT SALES_FK1 FOREIGN KEY (customerID) REFERENCES CUSTOMERS(customerID),
CONSTRAINT SALES_FK2 FOREIGN KEY (vehicleVIN) REFERENCES VEHICLES(vehicleVIN));
And built the following query to run off of these tables:
SELECT VEHICLES.vehicleMake, CUSTOMERS.customerFullName
FROM SALES
JOIN CUSTOMERS on SALES.customerID = CUSTOMERS.customerID
JOIN(
SELECT SALES.vehicleVIN, VEHICLES.vehicleMake
FROM SALES
JOIN VEHICLES ON SALES.vehicleVIN = VEHICLES.vehicleVIN
GROUP BY SALES.vehicleVIN, VEHICLES.vehicleMake
HAVING COUNT(SALES.vehicleVIN) >= ALL
(SELECT COUNT(SALES.vehicleVIN)
FROM SALES
INNER JOIN VEHICLES ON SALES.vehicleVIN=VEHICLES.vehicleVIN
GROUP BY VEHICLES.vehicleMake))
VEHICLES ON SALES.vehicleVIN = VEHICLES.vehicleVIN
ORDER BY CUSTOMERS.customerFullName;
When I run this in SQL Fiddle, it executes perfectly and provides the correct output (one column that displays the vehicleMake that was purchased the most, and another column that displays the customerFullName of everyone who purchased that vehicleMake).
When I run it in NOVA (Oracle), It just says "No Rows Selected" Is there a difference in syntax between the two? Do I need to change my code? Thanks!