Junior — Middle
Can you write a query using JOIN to connect tables in SQL?
sobes.tech AI
Answer from AI
An example SQL query using JOIN to connect two tables, such as users and orders, where you need to get a list of users and their orders:
SELECT users.id, users.name, orders.id AS order_id, orders.amount
FROM users
JOIN orders ON users.id = orders.user_id;
Here, JOIN connects the tables based on the condition users.id = orders.user_id, returning rows where there are matches in both tables. Different types of JOINs (INNER JOIN, LEFT JOIN, etc.) can be used depending on the task.