Assuming you have these two MySQL tables
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
customers +--+------------------+-------------------+ |id|name |address | +--+------------------+-------------------+ | 1| Leanne Graham |4208 Shobe Lane | | 2| Janet Pruett |1462 Hamilton Drive| +--+------------------+-------------------+ credit-cards +--+------------+------------+ |id|costumers_id| expiry_date| +--+------------+------------+ | 1| 1| 2009-11-17| | 2| 2| 2030-12-31| +--+------------+------------+ |
You can ask MySQL to show you all customers who has a valid credit card
1 2 3 4 5 6 7 8 |
SELECT c.id, c.name, c.address, cc.expiry_date FROM customers AS c LEFT JOIN credit-cards AS cc ON c.id = cc.parent_id WHERE cc.expiry_date > now() |
MySQL output
1 2 3 4 5 |
+----+------------+-------------------+--------------+ |c.id|c.name |c.address |cc.expiry_date| +----+------------+----------------------------------+ | 1|Janet Pruett|1462 Hamilton Drive| 2030-12-31| +----+------------+-------------------+--------------+ |