Assuming you have these two MySQL tables
|
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
|
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
|
+----+------------+-------------------+--------------+ |c.id|c.name |c.address |cc.expiry_date| +----+------------+----------------------------------+ | 1|Janet Pruett|1462 Hamilton Drive| 2030-12-31| +----+------------+-------------------+--------------+ |