Home > OS >  Querying database tables using SQL
Querying database tables using SQL

Time:05-03

Currently doing a project in android studio in java and I'm trying to query two tables in sql. The tables are as follows:

Bookings table

Bookings table

User_Bookings table

User_Bookings table

User table just for reference

enter image description here

Is there a way do to a UNION or INNER JOIN and connect these two tables with just the userID ?

Say for example for the user with ID 2 I want from the Bookings table the departure time & departure date (12:30 & 12/5/20222) and from the User_Bookings table I want the number of people (2).

Or is UNION/INNER JOIN not the right operators for what I am trying to achieve ? As I have been trying and brushing up on my SQL skills but I can't seem to get ahead of it.

Any help appreciated.

CodePudding user response:

SELECT * FROM Bookings b INNER JOIN User_Bookings ub ON b.bookingID=ub.bookingID where ub.userID = <pass_parameter_actual_userID>
  • Related