DECLARE @str NVARCHAR(Max)
SELECT @str = COALESCE(@str + ';', '') + columnname FROM tablename
SELECT @str
SELECT id, first_name, last_name, age, subject FROM student_details;
SELECT * FROM student_details;
SELECT subject, count(subject)
FROM student_details
WHERE subject != 'Science'
AND subject != 'Maths'
GROUP BY subject;
SELECT subject, count(subject)
FROM student_details
GROUP BY subject
HAVING subject!= 'Vancouver' AND subject!= 'Toronto';
SELECT name
FROM employee
WHERE (salary, age ) = (SELECT MAX (salary), MAX (age)
FROM employee_details)
AND dept = 'Electronics';
SELECT name
FROM employee
WHERE salary = (SELECT MAX(salary) FROM employee_details)
AND age = (SELECT MAX(age) FROM employee_details)
AND emp_dept = 'Electronics';
Select * from product p
where EXISTS
(select * from order_items o
where o.product_id = p.product_id)
Select * from product p
where product_id IN
(select product_id from order_items
SELECT d.dept_id, d.dept
FROM dept d
WHERE EXISTS ( SELECT 'X'
FROM employee e
WHERE e.dept = d.dept);
SELECT DISTINCT d.dept_id, d.dept
FROM dept d,employee e
WHERE e.dept = e.dept;
SELECT id, first_name
FROM student_details_class10
UNION ALL
SELECT id, first_name
FROM sports_team;
SELECT id, first_name, subject
FROM student_details_class10
UNION
SELECT id, first_name
FROM sports_team;
SELECT id, first_name, age FROM student_details WHERE age > 10;
SELECT id, first_name, age FROM student_details WHERE age != 10;
SELECT id, first_name, age
FROM student_details
WHERE first_name LIKE 'Chan%';
SELECT id, first_name, age
FROM student_details
WHERE SUBSTR(first_name,1,3) = 'Cha';
SELECT id, first_name, age
FROM student_details
WHERE first_name LIKE NVL ( :name, '%');
SELECT id, first_name, age
FROM student_details
WHERE first_name = NVL ( :name, first_name);
SELECT product_id, product_name
FROM product
WHERE unit_price BETWEEN MAX(unit_price) and MIN(unit_price)
SELECT product_id, product_name
FROM product
WHERE unit_price >= MAX(unit_price)
and unit_price <= MIN(unit_price)
SELECT id, name, salary
FROM employee
WHERE dept = 'Electronics'
AND location = 'Bangalore';
SELECT id, name, salary
FROM employee
WHERE dept || location= 'ElectronicsBangalore';
SELECT id, name, salary
FROM employee
WHERE salary < 25000;
SELECT id, name, salary
FROM employee
WHERE salary + 10000 < 35000;
SELECT id, first_name, age
FROM student_details
WHERE age > 10;
SELECT id, first_name, age
FROM student_details
WHERE age NOT = 10;
SELECT id
FROM employee
WHERE name LIKE 'Ramesh%'
and location = 'Bangalore';
SELECT DECODE(location,'Bangalore',id,NULL) id
FROM employee
WHERE name LIKE 'Ramesh%';
SELECT TOP 1 salary FROM (SELECT DISTINCT TOP n salaryFROM employee ORDER BY salary DESC) aORDER BY salary
delete |
FROM Exam_Backup |
WHERE ID NOT IN (SELECT MAX(ID) FROM Exam_Backup GROUP BY QuestionNo) and optionName=0 |
DECLARE cIX CURSOR FOR SELECT OBJECT_NAME(SI.Object_ID), SI.Object_ID, SI.Name, SI.Index_ID FROM Sys.Indexes SI ...