Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

SQL Query

Posted on 2012-03-25
2
Medium Priority
?
337 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 8

Accepted Solution

by:
fundacionrts earned 2000 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

Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

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

What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Ready to get certified? Check out some courses that help you prepare for third-party exams.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

719 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