Yugander Krishan Singh Yugander Krishan Singh - 5 months ago 23
Java Question

Select query in MySql table

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
fetches a set of rows but is there a way to modify this sql query so that it fetches me the very first row of table2 where id column is null.

Max Max
Answer Source
select * from table2 where id is null limit 1

Limit specifies number of records you want to fetch.