Given a Student table, Swap all Male to Female value and vice versa with a single update query.
Id Name Sex Salary
----------------------------
1 Ranga Male 2500
2 Vasu Female 1500
3 Raja Male 5500
4 Amma Female 500
Program:
------------------------
UPDATE Gender SET sex = CASE sex WHEN 'Male' THEN 'Female' ELSE 'Male' END
Sunday, May 17, 2015
Home »
Interview Questions
,
MySQL
,
Programs
,
SQL
» Write a SQL Program to Swap the values in a single update query.
Write a SQL Program to Swap the values in a single update query.
Related Posts:
What is the output of the following SQL Program. SELECT CASE WHEN null = null THEN 'I LOVE YOU RANGA' ELSE 'I HATE YOU RANGA' end as Message;SELECT CASE WHEN null = null THEN 'I LOVE YOU RANGA' ELSE 'I HATE YOU RANGA' end as Message;Output: 'I HATE YOU RANGA'The reason for this is that the proper way to compare a value to null in SQL is with the is&… Read More
Write a SQL Program to Get the Next and Previous values based on Current value?CREATE TABLE student (id int, name varchar(30), age int, gender char(6));INSERT INTO student VALUES (1 ,'Ranga', 27, 'Male'), (2 ,'Reddy', 26, 'Male'), (3 ,'Vasu', 50, 'Female'), (4 ,'Ranga', 27, 'Male'), (5 ,… Read More
Write a SQL Program to generate the following output?Input:Employee:Department:Output:Creating tables and inserting Data:CREATE TABLE Employee ( e_id INT NOT NULL AUTO_INCREMENT, e_name VARCHAR(100) NOT NULL, age tinyint NOT NULL, PRIMARY KEY (e_id));CREATE TABLE Depart… Read More
How to get the Duplicate and Unique Records by using SQL Query?CREATE TABLE student (id int, name varchar(30), age int, gender char(6));INSERT INTO student VALUES (1 ,'Ranga', 27, 'Male'), (2 ,'Reddy', 26, 'Male'), (3 ,'Vasu', 50, 'Female'), (4 ,'Ranga', 27, 'Male'), (5 ,… Read More
Hibernate4 One-to-One Relationship Example Using AnnotationsIn this article we are going to create a project to implement step by step one-to-one association example using Annotations with Maven project.OneToOne Relationship:A one-to-one relationship occurs when one entity is related … Read More
0 comments:
Post a Comment