Home Answers Viewqa SQL Update a group of records with one value in the same group

 
 


Suresh Satti
Update a group of records with one value in the same group
1 Answer(s)      6 months and 9 days ago
Posted in : SQL

I want to update my table group wise, i have three cases AA,BB,CC , if group of records haveing one AA value in name column then those records NAME column should be update with AA. If group is not having AA value second priority is BB next CC. If group does not have AA,BB,CC value then remains same (no need to update) . source Table. ID Name 11 AA 11 BB 11 CC 12 CC 12 02 12 BB 13 CC 13 03 13 45 13 65 14 02 14 05 15 12

Required result table: ID NAME 11 AA 11 AA 11 AA 12 BB 12 BB 12 BB 13 CC 13 CC 13 CC 13 CC 14 02 14 05 15 12

View Answers

December 10, 2012 at 4:06 PM


-- STEP 1: SELECT ID,Name, CASE WHEN Name LIKE 'AA' THEN 4 WHEN Name LIKE 'BB' THEN 3 WHEN Name LIKE 'CC' THEN 2 WHEN Name LIKE 'DD' THEN 1 ELSE 0 END AS HighRank INTO #Result1 FROM dbo.satti

-- STEP 2:

UPDATE Orginal SET Orginal.Name = Tmp1.Name FROM dbo.satti Orginal INNER JOIN( SELECT A.ID,A.Name,A.HighRank FROM #Result1 A INNER JOIN( SELECT ID,MAX(HighRank) AS High from #Result1 WHERE HighRank <> 0 GROUP BY ID) Temp ON A.ID = Temp.ID AND A.HighRank = Temp.High)Tmp1 ON Orginal.ID = Tmp1.ID









Related Pages:
Update a group of records with one value in the same group
Update a group of records with one value in the same group  I want to update my table group wise, i have three cases AA,BB,CC , if group of records.... If group does not have AA,BB,CC value then remains same (no need to update) . source
Mysql Group By
to group the result-set by specified one or more columns. Understand with Example... by clause: The Query group by is used to return the selected records from 'employee... Mysql Group By      
Mysql Group By
functions to group the result-set by specified one or more columns. Understand... group by clause: The Query group by is used to return the selected records from... Mysql Group By      
SQL Avg Group By
SQL Avg Group By       SQL Avg Group By helps you to find out average value of numeric field in a table. The SQL GROUP BY clause is used with the SQL aggregate functions
SQL GROUP BY Example
. GROUP BY clause groups the same types of records of a table. This clause can... : select item, sum(quantity) from `order` group by item Now the records...SQL GROUP BY Example In this section we will discuss about the group
SQL Aggregate Functions Group By
SQL Aggregate Functions Group By       SQL Aggregate Functions Group By return the aggregate functions (like SUM) of the different numeric field for each individual group
SQL Avg Group By
SQL Avg Group By       SQL Avg Group By helps you to find out average value of numeric field... the average marks  records of a numeric field in a table. The Group
SQL Aggregate Functions Group By
)); Insert Value Into Stu_Table The insert into statement add the records... SQL Aggregate Functions Group By       SQL Aggregate Functions Group By return the aggregate
Group Discussion Dos and Don’ts
for a group discussion. There are two parts to it. One is that you need to be well... Group Discussion Dos and Don’ts       Introduction Group discussions are today an important
Hibernate GROUP BY Clause
Hibernate GROUP BY Clause In this tutorial you will learn how to use HQL GROUP BY clause. GROUP BY clause in HQL is used as same as it is used in SQL... the results that may be grouped in one or more columns. Example Here I am giving
GROUP BY IN NESTED QUERY
GROUP BY IN NESTED QUERY  Hello Every One, Query to use GROUP BY CLAUSE IN NESTED QUERY SELECT STATEMENT in mysql database.If u know please help me.thanks
group by sorting
group by sorting  group by sorting of data in SQL
How to iterate over a checkbox group
group - it's id equals "MASTER" - contains 4 checkboxes. These checkboxes... group to appear below the MASTER group. If a user then checks "B" in MASTER, then the "B" group appears below the "A" group. If the user then unchecks
Hibernate Criteria Group By
Hibernate Criteria Group By The Hibernate Criteria Group By is used to display the records in a group on the basis of class properties. You can display records in Group By in a following way Criteria criteria
JDBC: Update Records Example
JDBC: Update Records Example In this section, you will learn how to update records of the table using JDBC API. Update Records : Update record is most important operation of database. If you want to change one field value of a record
HQL group By.
HQL group By.  How to use group by in HQL?   In general group by clause is used with aggregate functions for grouping the result... order. It allows the Hibernate to fetch information from the database and group
Using the Captured Text of a Group within a Replacement Pattern
Using the Captured Text of a Group within a Replacement Pattern... how to use the captured text from the group of the text. This section... expression of the code which has been used to capture each and every word one by one
multiple records on same panel
multiple records on same panel  i have multiple access of records and i want to display all of them at one panel.Each time a new panel opens for a keyrecord , i want just to show records on same panel or frame, whatever u can
PHP Mysql Group By
the maximum marks, Id and name records to group the result set by column id from... PHP Mysql Group By       PHP Mysql Group By is used to establish a relation between the PHP
JPA Query with where clause and group by function
JPA Query with where clause and group by function  Any thing wrong... BETWEEN :startDate AND :endDate GROUP BY activePackage",User.class); List<... listOfPackages; I am getting the IllegalStatementException.Can any one help me
updating rows which contains same id, different value for each row
rows with sid 5. Like this table may contains multiple records with same sid. Here my requirement is "I have to update those records which contains same sid...updating rows which contains same id, different value for each row  
SQLl query count and group by
SQLl query count and group by  How to write a sql query to count and group by the data?   Sql query to count the data and group the data using group by function... Select Name, Count(Name) As Count From Table Group
xcode group folder
xcode group folder  I wanted to show all files in xcode in a group format.. left and right Group & Files. earlier it was showing in groups... the steps.. View -> Smart Groups -> All Files it'll group all the files
Update Records in Database
Update Records in Database       The Update Records in database is used to modify or change the value of records which match with a specified criteria. The update query
insert/update records with some of the columns having NULL value.
insert/update records with some of the columns having NULL value.  How do I insert/update records with some of the columns having NULL value
Hibernate Group by Clause
In this tutorial we will discuss about Hibernate group by with example
how to use group by in nested query
how to use group by in nested query  Hai, How to use group by clause in nested query select statement in subquery i am having where clause.please help me.thanks in advance
Use Group Class in SWT
Use Group Class in SWT       In this section, you will learn how to use Group class. In SWT, the class Group of package org.eclipse.swt.widgets provides an etched border
update the selected records from view immediatly
update the selected records from view immediatly  Hi I am extracting data form sql view to Excel(2007). I want update the Flag field (CHAR 1)in one... update the records immedialty in view as soon as see the data form view. Thank
HQL Group By Clause Example
HQL Group By Clause Example       Group by clause is used to return the aggregate values by grouping on returned component. HQL supports Group By Clause. In our example we
Radio Buttons
) are used in groups (java.awt.ButtonGroup) where at most one can be selected. The example below produced this image. A radio button group starts with all buttons deselected, but after one is selected the only way to have them appear all
Hash value is not same - Java Beginners
Hash value is not same  Hi, I've two Excel files with same data.... I've generated one way hash using SHA-1 algorithm. But the hash value of Excel 2003 files is not same as the hash value of Excel 2007 file. What might
Group Container in Flex4
Group container in Flex4: The Spark Group containers take any components...) you can use Group container. The Group container is designed for simplicity... of the Group container. You can use Horizontal and Vertical layout with Group
Use of <sql:transaction> tag of jstl
application that how to group queries and update operations by using <sql:transaction> tag of jstl. To execute query and update database first create...:transaction> :  This tag provides facility to execute group query
MySQL Addition
; MySQL Addition returns you the sum value of a specific column for a group... Query. We can make use of Aggregate function with group by and order by clause.... The select order by query is used to sort the records by specific column. In this example
Capturing Text in a Group in a Regular Expression
Capturing Text in a Group in a Regular Expression  ... the text in a group through the regular expression. Here, you can learn... of the program "a", "b" and "c") from the group of text
Column Group in AdvancedDataGrid
Column Group in AdvancedDataGrid in Flex4: In this example you can see how we can create a column group for two or more then two columns. The tag of column group is <mx:AdvancedDataGridColumnGroup>. Example: <?xml
employee records
employee records  Pl give one script like i will creat one table name Emp_master and column name like Empcode, Empname. I like one form where I will enter New record and another form like emp_code query and update or delete
employee records
employee records  Pl give one script like i will creat one table name Emp_master and column name like Empcode, Empname. I like one form where I will enter New record and another form like emp_code query and update or delete
employee records
employee records  Pl give one script like i will creat one table name Emp_master and column name like Empcode, Empname. I like one form where I will enter New record and another form like emp_code query and update or delete
Adding Horizontal lines to Group Nodes
Adding Horizontal lines to Group Nodes       Introduction In this section, you...: This is the client property value. Here is the code of this program: import 
Update value
Update value  How to update value of database using hibernate ?   Hi Samar, With the help of this code, you will see how can update database using hibernate. package net.roseindia.DAO; import
Data Manipulation Statements
( ) function return the maximum value in a group of records. Example of the MAX... minimum value in a group of records. Example of the MIN( ) function:- ... is used to retrieve a result set of records from one or more tables, temporary tables
java source code to send group mails using struts2
java source code to send group mails using struts2  code to send group mails using struts2
update
update  how can i update multiple records in database using jsp ,servlet and jdbc based on selection of checkbox in jsp
JDBC batch update
JDBC batch update       JDBC batch update is a collectively called when a group of SQL statements.... This method return you the modify value in the database using update query in the sql
Mysql Update command
Mysql Update       Mysql Update Mysql Update is used to modify the table and set a new value to the column on the basis of condition specified in where
how can i do group tagging in portlet factory
how can i do group tagging in portlet factory  how can i do group tagging in portlet factory
HAVING Clause in JPQL (Java Persistence Query Language)
: The HAVING clause is used to combine with the GROUP BY clause. It can be used with the SELECT statement to filter the records. A HAVING clause restricts the query results of a GROUP BY in the SelectExpression. This clause is applied
update
written by the developer to update the Status table: String str = "UPDATE m...://localhost:3306/roseindia", "root", "root"); String str = "UPDATE Status SET name= ?,value=? WHERE id= 1 "; PreparedStatement ps

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.