-3

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.

5
  • Do you realize that you are doing cross join between all the three tables? Mar 28, 2017 at 17:44
  • No, what should i do in this case?
    – Mark Jason
    Mar 28, 2017 at 17:46
  • at your near FROM probably means that semicolon in the select clause but I don't think your joins will work like you think Mar 28, 2017 at 17:46
  • 1
    @MarkJason - Join them on related columns. If still not clear, post table schema, sample data and desired output. Mar 28, 2017 at 17:47
  • I added some data
    – Mark Jason
    Mar 28, 2017 at 17:53

1 Answer 1

0

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.

2
  • "ERROR: column reference "flightid" is ambiguous LINE 1: SELECT flightid,flightdate,numseats,seatnumber,maxcapacity"
    – Mark Jason
    Mar 28, 2017 at 17:42
  • @MarkJason: That means you probably have a flightid column in more than one table. You will have to change your SELECT to something like SELECT flight.flightid,... Mar 28, 2017 at 17:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.