I’m using php and MySQL. I have two tables. I want to select all the records from table PARTS that have the same prod_name as the most recently added record in the table PRODUCTS.
Table PRODUCTS:
- id (auto increment)
- prod_name
Table PARTS:
- prod_name
- part_name
- part_cost
Will this work or should I use some sort of join?
SELECT * FROM parts WHERE prod_name = (SELECT prod_name FROM products ORDER BY id DESC LIMIT 1)
Yes it will work. You can always execute the query in the phpmyadmin or MySql Query Browser to test it.
It may be better to return the inserted id, and select using that id.