Let’s call this table customers
:
+----+-------------+
| id | name |
+----+-------------+
| 1 | roger |
| 2 | steve |
| 3 | harold |
| 4 | tom |
+----+-------------+
And this is table orders
:
+----------+-------------+---------+
| order_id | customer_id | total |
+----------+-------------+---------+
| 101 | 1 | 25 |
| 102 | 1 | 18 |
| 103 | 3 | 149 |
| 104 | 4 | 299 |
+----------+-------------+---------+
How can I select only the rows in table customers
only if it has a row in the orders
table (by ensuring customers.id
matches the orders.customer_id
(and also ignore the duplicates)?