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.

1 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

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -