sql - select first record into field1 and other records into field2 -
i have table1 id's. table2 2 fields; master, , child.
i need select first id table1 master in table2, , other ids child in table2.
tried this:
dim rs recordset dim strsql string strsql = "select top 1 id table1" set rs = currentdb.openrecordset(strsql) rs.movefirst strsql = "insert table2 (child) select table1.id table1 id <> " & rs.fields(0).value docmd.runsql strsql strsql = "update table2 set master = " & rs.fields(0).value & " master null" docmd.runsql strsql rs.close set rs = nothing
but since have same thing different tables many times in code, i'd rather if possible 1 query. if possible without subquery well.
you can use supposing id numeric column
select table2.id, table2.child (select min(id) master table1) table1 inner join table2 on table1.master = table2.id
i don't see way without subquery.
Comments
Post a Comment