Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Haider's avatar

[Database] - Need a suggestion for an SQL query

I am working on Bus Seat Booking System. This is the table where I am storing the reserved seats data.

SELECT `id`, `SeatNumber`, `UserID`, `PlateNumber` FROM `seating`
//id is Primary Key
//UserID foreign key
//PlateNumber foreign key

I want an SQL Query that picks up results such that

  1. User cannot see his own reserved seats
  2. User cannot see other passenger seats
  3. User cannot see seats reserved on other bus.

Currently I have thought of a following query but it doesn't work fully on above conditions. Suggest some ideas.

SELECT SeatNumber from seating where UserID not in(1) or PlateNumber in('B6551');
0 likes
4 replies
jlrdw's avatar

User cannot see his own reserved seats

What can the user see?

Haider's avatar

@jlrdw From that i mean if the user has booked some seats on a bus, and visits again to book some more, he cannot view the previous ones.

jlrdw's avatar

Then it's like anyone (doesn't matter) is booking, so change the query to show available seating. That would exclude already taken seats.

Please or to participate in this conversation.