Sobes.tech
Middle

Write an SQL query that retrieves all rows from products and adds the corresponding name from users (owner_id linked to id in users).

sobes.tech AI

Answer from AI

sql SELECT p.*, u.name FROM products p LEFT JOIN users u ON p.owner_id = u.id;


This query selects all columns from the `products` table and adds the `name` field from the `users` table to each row, where `owner_id` in `products` matches `id` in `users`. It uses `LEFT JOIN` to display all products, even if some do not have a corresponding user.