Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
mbr table

mid    mnum
1      10
1      11
2      12
2      13
3      14
3      15


nm table

mnum   name
10      x
11      x
11      x
12      y
13      y
14      z
15      z
14      z


expected output

nm table

mnum   name
10      x
10      x
10      x
12      y
12      y
14      z
14      z
14      z


as there are so many rows i want a query that update all the rows with out hard coded values

What I have tried:

i tried with logic of selecting max mnum from mbr table and select min mnum from nm table and use update query to update max to min.it is updating every thing
Posted
Updated 3-Feb-20 4:12am
Comments
CHill60 3-Feb-20 10:05am    
Show the code you tried

1 solution

Your question is not particularly clear, but the following query should produce your expected output:
SQL
UPDATE
    nm
SET
    mnum = (SELECT Min(mnum) FROM nm As N2 WHERE N2.name = nm.name)
; 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900