Solved

SQL Query

Posted on 2012-03-25
2
330 Views
Last Modified: 2012-03-25
I have a table as below

Material   SeqNum   Controlkey
22             1                  x
22             2                  x
22             3                  x
22             4                  x
24             1                  x
24             2                  x

I have to update controlkey='y' for the max(seqno) for each material. I came up with the query

update Table_3
set ckey='ybp3'
from Table_3
where seqno=(select MAX(seqno)
from Table_3
group by Material)

But this is giving me two values in subquery . Here in the above query I need to update table as

Material   SeqNum   Controlkey
22             1                  x
22             2                  x
22             3                  x
22             4                  y
24             1                  x
24             2                  y


Thanks !
0
Comment
Question by:himabindu_nvn
2 Comments
 
LVL 8

Accepted Solution

by:
fundacionrts earned 500 total points
ID: 37762958
update
      Table_3_update
set
      ckey='ybp3'
from
      Table_3 Table_3_update
where
      seqno=(select MAX(seqno)
                  from Table_3 t3
                  where t3.Material = Table_3_update.Material
                  group by Material)
0
 

Author Closing Comment

by:himabindu_nvn
ID: 37762973
Thank you!
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now