Home > Enterprise >  How to execute SQL query for selection of info from more than 1 table
How to execute SQL query for selection of info from more than 1 table

Time:04-22

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:

  1. user_id, name, surname, telephone_number

  2. appointment_id, user_id, appointment_date_time

  3. 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

  4. Sort the time of the appointments so that it will be: 9:00, 10:00, 12:00, 14:00, 15:00

  5. Select user_ids of the bookings from 'appointments'

  6. 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";
  • Related