Search code examples
sqlpgadmin-4

Why doesn't my query work? (SQL)


Here is my code

SELECT flightid,flightdate,numseats,seatnumber,maxcapacity;
FROM flight,flightbooking,seatbooking;

I get and error saying:

"ERROR:  syntax error at or near "FROM"
LINE 2: FROM flight,flightbooking,seatbooking;"
        ^

These are my tables

LeadCustomer (CustomerID, FirstName, Surname, BillingAddress, email) Passenger(PassengerID, FirstName, Surname, PassportNo, Nationality, DoB)

Flight (FlightID, FlightDate, Origin, Destination, MaxCapacity, PricePerSeat)

FlightBooking (BookingID, CustomerID, FlightID, NumSeats, Status, BookingTime, TotalCost)

SeatBooking(BookingID, PassengerID, SeatNumber)

This is what i am trying to achieve

"Check the availability of seats on all flights by showing the flight ID number, flight date along with the number of booked seats, number of available seats and maximum capacity."

The software i am using is PG Admin 4. Thanks.


Solution

  • Remove the semicolon at the end of the SELECT line, that should fix it.

    Try:

    SELECT flightid, flightdate, numseats, seatnumber, maxcapacity
    FROM flight, flightbooking, seatbooking;
    

    Of course, I'm not sure this query will be much better. There are no JOIN conditions on these tables or WHERE clauses to filter results.