SQL query seems to have an Error - sql

I have a DBF - foxpro query and seems like I have an error, I am using codeIgniter and its feedback is just Fatal error: Call to a member function execute() on a non-object in D:\xampp\htdocs\accounting\system\database\drivers\pdo\pdo_driver.php on line 193 and I have encountered this error many times already and it means I have an error in my SQL but I cant figure out where. here are my tables
GUESTS
Guest ID | Guest_Name | Guest_Seat_No
1 | John | 24
SEATS
Seat_No | Room_Location
24 | 2nd Floor Room 11
HERE IS MY SQL QUERY
SELECT A.Guest_ID, A.Guest_Name, A.Guest_Seat_No, B.Room_Location
FROM GUESTS A JOIN SEATS B
ON A.Guest_Seat_No = B.Seat_No
WHERE A.Guest_ID = '1'
It seems there's something wrong in my query, its very difficult to determine the error because it just returns a fatal error generated by codeIgniter not the actual sql syntax error can someone please help me?

you should define what kind of JOIN type you are using, like INNER , LEFT, OUTER, FULL,

SELECT A.Guest_ID, A.Guest_Name, A.Guest_Seat_No, B.Room_Location
FROM GUESTS AS A
JOIN SEATS AS B ON A.Guest_Seat_No = B.Seat_No
WHERE A.Guest_ID = '1'

Whew, I cant believe I got stuck on this just because of the word INNER in INNER JOIN I usually use just JOIN because knowing INNER JOIN is the default right? maybe DBF foxpro really wants the keyword INNER in JOIN statement :) strict fellow. Anyway Thanks to all of you for the help.
SELECT A.Guest_ID, A.Guest_Name, A.Guest_Seat_No, B.Room_Location
FROM GUESTS A INNER JOIN SEATS B
ON A.Guest_Seat_No = B.Seat_No
WHERE A.Guest_ID = '1'

Related

Join with Multiple Tables

I am getting a syntax error with the following problem and can't seem to figure out, hope you guys can help me!
I have these tables (they are populated):
I am trying to retrieve the first and last name of all the passengers scheduled in a certain flight number so what I have is this:
SELECT PassFName, PassLName
FROM Passenger
INNER JOIN PassID ON Passenger.PassID = Reservation.PassID
INNER JOIN FlightNum ON FlightNum.Reservation = FlightNum.ScheduledFlight
WHERE ScheduledFlight.FlightNum = [Enter Flight Number];
However, I am getting error:
Not sure why and I have also noticed in the last line it is misspelling FlightNum.ScheduledFlight. Any idea what am I doing wrong?
Thank you!
Gordon's point is valid, but he's got his parentheses misplaced and missed the other big issues. This query is more than a little whacked, with table names and field names flip-flopped. Here's what I would guess would work...
SELECT
PassFName
, PassLName
FROM (
Passenger
INNER JOIN Reservation
ON Passenger.PassID = Reservation.PassID
)
INNER JOIN ScheduledFlight
ON Reservation.FlightNum = ScheduledFlight.FlightNum
WHERE
ScheduledFlight.FlightNum = [Enter Flight Number];
MS Access has a strange syntax for joins. It requires parentheses around each JOIN pair. So:
SELECT PassFName, PassLName
FROM (Passenger INNER JOIN
Reservation
) ON Passenger.PassID = Reservation.PassID INNER JOIN
FlightNum
ON FlightNum.Reservation = FlightNum.ScheduledFlight
WHERE ScheduledFlight.FlightNum = [Enter Flight Number];
Although other databases support this syntax, it is only required in MS Access.

SQL Server : multi-join with tuple IN clause

I'm trying to join 4 tables that have a somewhat complex relationship. Because of where this will be used, it needs to be contained in a single query, but I'm having trouble since the primary query and the IN clause query both join 2 tables together and the lookup is on two columns.
The goal is to input a SalesNum and SalesType and have it return the Price
Tables and relationships:
sdShipping
SalesNum[1]
SalesType[2]
Weight[3]
sdSales
SalesNum[1]
SalesType[2]
Zip[4]
spZones
Zip[4]
Zone[5]
spPrices
Zone[5]
Price
Weight[3]
Here's my latest attempt in T-SQL:
SELECT
spp.Price
FROM
spZones AS spz
LEFT OUTER JOIN
spPrices AS spp ON spz.Zone = spp.Zone
WHERE
(spp.Weight, spz.Zip) IN (SELECT ship.Weight, sales.Zip
FROM sdShipping AS ship
LEFT OUTER JOIN sdSales AS sales ON sales.SalesNum = ship.SalesNum
AND sales.SalesType = ship.SalesType
WHERE sales.SalesNum = (?)
AND ship.SalesType = (?));
SQL Server Management Studio says I have an error in my syntax near ',' (appropriately useless error message). Does anybody have any idea whether this is even allowed in Microsoft's version of SQL? Is there perhaps another way to accomplish it? I've seen the multi-key IN questions answered on here, but never in the case where both sides require a JOIN.
Many databases do support IN on tuples. SQL Server is not one of them.
Use EXISTS instead:
SELECT spp.Price
FROM spZones spz LEFT OUTER JOIN
spPrices spp
ON spz.Zone = spp.Zone
WHERE EXISTS (SELECT 1
FROM sdShipping ship LEFT JOIN
sdSales sales
ON sales.SalesNum = ship.SalesNum AND
sales.SalesType = ship.SalesType
WHERE spp.Weight = ship.Weight AND spz.Zip = sales.Zip AND
sales.SalesNum = (?) AND
ship.SalesType = (?)
);

MS Access 2016 Error: "Multi-level group by not allowed"

i'm stuck at another point in my little Access 2016 Database. My code looks like the following and i know it probably isn't the cleanest solution but i'm kinda new to this and i tried to educate myself and get some help here already.
I'm trying to play around with the reports now a little bit and i am using this test query which returns all entries of two tables joined together.
As far as i could find out I have this one subquery included that returns the prvious day inventory for each record and that is most likely the cause of my error. I found a possible solution with adding SELECT * FROM at the beginning of my code but i get a Syntax error when i do that and i'm not sure how to solve this problem.
here's my code
SELECT Stations.StationName, Product.ProductName, GasInventoryTransactions.TransactionDate, (SELECT TOP 1 Dupe.ActualInventory FROM GasInventory AS Dupe WHERE Dupe.StationID = Stations.StationID AND Dupe.ProductID = Product.ProductID AND Dupe.InventoryDate < GasInventory.InventoryDate ORDER BY Dupe.InventoryDate DESC) AS PreviousDayInventory, GasInventory.ActualInventory, GasInventoryTransactions.GasSales, GasInventoryTransactions.GasDelivery, [PreviousDayInventory]+[GasDelivery]-[GasSales] AS BookBalance, GasInventory.ActualInventory, [ActualInventory]-[BookBalance] AS OverShort
FROM (Stations INNER JOIN (Product INNER JOIN GasInventory ON Product.[ProductID] = GasInventory.[ProductID]) ON Stations.[StationID] = GasInventory.[StationID]) INNER JOIN GasInventoryTransactions ON GasInventory.[InventoryDate] = GasInventoryTransactions.[TransactionDate];
thanks for your help!

EXCEL VBA/ADODB Connection / LEFT JOIN 3 tables SQL - Syntax Error

I have a workbook set up with 3 separate tabs/tables, and I am trying to do a 3 way LEFT JOIN query on this workbook (using SQL via the commandtext box on the ADODB connection in Excel 03), and I get a Syntax Error (Missing Operator) msgbox:
SELECT B.[Business], A.[book], C.[bus_area]
FROM [Bon$] as A LEFT JOIN [DM$] as B ON (A.[book] = B.[SystemBookName] )
LEFT JOIN [BA$] as C ON B.[SystemBookName] = C.[portfolio_name]
WHERE A.[area] NOT LIKE "%TEST%"
I know this is probably due to some syntax error/ or where I place the paranthesis, but I tried multiple combinations and it does not seem to work. Any ideas?
Many thanks
Ah I figured out why. The code was thrown out because it saw it missing the operator FROM before the second LEFT JOIN. So I put in paranthesis everything after FROM and the second LEFT JOIN and it worked.
SELECT B.[Business], A.[book], C.[bus_area]
FROM ([Bon$] as A LEFT JOIN [DM$] as B ON A.[book] = B.[SystemBookName] )
LEFT JOIN [BA$] as C ON B.[SystemBookName] = C.[portfolio_name]
WHERE A.[area] NOT LIKE "%TEST%"

"Error: Unexpected, Please Try Again" with GoogleBigQuery JOIN

I know this is an older issue with Google BigQuery, but it seems the problem had been fixed # mid 2013. I wanted to know if there has been any recent workarounds/fixes to this issue in the recent months. Here is my query from the google sample data.
SELECT publicdata:samples.natality.mother_age, publicdata:samples.gsod.station_number
FROM [publicdata:samples.natality]
INNER JOIN [publicdata:samples.gsod]
ON publicdata:samples.gsod.year = publicdata:samples.natality.year
LIMIT 100
Query Failed
Error: Unexpected. Please try again.
Job ID: deft-grammar-553:job_eUkW4EhgNvlJPuWPoP1bLL7Ra_w
Thanks for the report! That error message should be improved.
In the meantime: The same query using table aliases works well (though I had to change the JOIN to JOIN EACH to deal with the size of both tables).
Instead of:
SELECT publicdata:samples.natality.mother_age, publicdata:samples.gsod.station_number
FROM [publicdata:samples.natality]
INNER JOIN [publicdata:samples.gsod]
ON publicdata:samples.gsod.year = publicdata:samples.natality.year
LIMIT 100
Do:
SELECT a.mother_age, b.station_number
FROM [publicdata:samples.natality] a
INNER JOIN EACH [publicdata:samples.gsod] b
ON a.year = b.year
LIMIT 100