0

How Select data with two parameter in same rows?

My query not working, My query : select name from student_exam where exam_id = 1 && exam_id= 2 group by name

21st Jul 2020, 2:41 AM
Junaedi
Junaedi - avatar
9 ответов
+ 1
IIRC 'AND' is used in SQL instead of '&&'. Your condition doesn't make much sense, how can 'exam_id' value be 1 and 2 at the same time?
21st Jul 2020, 3:11 AM
Ipang
+ 1
Well, if you try to select something, which has to have two different values, where only one value can be, your result will always be empty.
21st Jul 2020, 3:11 AM
Sandra Meyer
Sandra Meyer - avatar
+ 1
Probably LIKE '%1%' OR LIKE '%2%'... Would return every id which contains a 1 or 2. If it's a string...
21st Jul 2020, 3:15 AM
Sandra Meyer
Sandra Meyer - avatar
0
Check the in-command. WHERE value IN ( a, b, c )
21st Jul 2020, 2:46 AM
Sandra Meyer
Sandra Meyer - avatar
0
Like i used OR,
21st Jul 2020, 2:52 AM
Junaedi
Junaedi - avatar
0
That's another possibility, but more to write. 😉 and less flexible.
21st Jul 2020, 2:53 AM
Sandra Meyer
Sandra Meyer - avatar
0
But i need data have two value using [AND],
21st Jul 2020, 3:04 AM
Junaedi
Junaedi - avatar
0
You want to select all exams with ID '1' or '2'. Right?
21st Jul 2020, 3:07 AM
Sandra Meyer
Sandra Meyer - avatar
0
Id = 1 AND id = 2
21st Jul 2020, 3:08 AM
Junaedi
Junaedi - avatar