I have two tables table1 which has id(primary key)and table2 which has an name, id(foreign key). All ids are null initially in table2. Now whenever a new id is generated in parent table we have to select the very first row from table2 which has id null and update that row with the new id. Now
select * from table2 where id is null
select * from table2 where id is null limit 1
Limit specifies number of records you want to fetch.