Solved

SQL Query

Posted on 2012-03-25
2
333 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Solar Winds can't see SQL Server Express 17 38
Requesting help with creating an SQL query with 2 tables 6 27
Dynamic SQL select query 4 40
What is this datetime? 1 20
Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

821 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