I wanted to select values from one table according to another table
I have a booking system with 'user' information table and 'appointment table', they have columns:
user_id, name, surname, telephone_number
appointment_id, user_id, appointment_date_time
I want to make a SQL query so that I can choose a date, for example, 20th of May and retrieve all the booking's on 20th of May, but in different times, like 12:00, 9:00, 14:00, 15:00, 10:00 and so on, as they are not ordered in the table
Sort the time of the appointments so that it will be: 9:00, 10:00, 12:00, 14:00, 15:00
Select user_ids of the bookings from 'appointments'
Select the user credentials through 'user' table like their names, surname, and phone number
At the end I am going to implement this into the admin panel So that when the admin will choose a specific date They can see all the appointment bookings, their time, and who booked them.
Could you please tell me what kind of query I can use (preferable a complex one) or direct me to useful and understandable resources?
CodePudding user response:
SELECT appointments.appointment_index, appointments.appointment_time, users.name,
users.surname, users.telnumber
FROM users
INNER JOIN appointments
ON users.user_id = appointments.user_id
WHERE appointment_date = '$date'
ORDER BY appointment_time";