I have the following table:
CREATE TABLE studenttest
(
YEAR INT,
DEPT VARCHAR(5),
SEM INT,
REGNO INT,
NAME VARCHAR(20),
ENGLISH VARCHAR(2),
MATHS VARCHAR(2),
PHYSICS VARCHAR(2),
CHEMISTRY VARCHAR(2),
EG VARCHAR(2),
FOC VARCHAR(2),
LAB1 VARCHAR(2),
LAB2 VARCHAR(2),
LAB3 VARCHAR(2)
)
With the following data:
INSERT INTO studenttest
values
(2010,'cse',3,1,'saravaanan','a','b','c','d','ra','f','g','h','i'),
(2010,'cse',3,2,'raja','ra','b','c','d','e','f','g','h','i'),
(2010,'cse',3,3,'selvam','a','b','c','d','e','f','g','h','i')
I want to query this data to get the result set of all the students who do not have a grade of "ra" in any of the subjects.
The MySQL UNION operator is used to combine the result sets of 2 or more SELECT statements. It removes duplicate rows between the various SELECT statements. Each SELECT statement within the UNION operator must have the same number of fields in the result sets with similar data types.
SELECT a.*
FROM studenttest a
LEFT JOIN
(
SELECT regno, name
FROM studenttest
WHERE ENGLISH = 'ra' OR
MATHS = 'ra' OR
PHYSICS = 'ra' OR
CHEMISTRY = 'ra' OR
EG = 'ra' OR
FOC = 'ra' OR
LAB1 = 'ra' OR
LAB2 = 'ra' OR
LAB3 = 'ra'
) b ON a.regno = b.regno
AND a.Name = b.Name -- this line is OPTIONAL
WHERE b.regno IS NULL
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With