Reputation: 1031
i have a table like this
id student teacher
10 a b
11 c b
12 d c
13 e b
student "e" is 3th student whose teacher is "b". how to get this with one query?
Upvotes: 0
Views: 77
Reputation: 10413
Very close to post from Secator
SELECT *
FROM (
SELECT (@row := @row + 1) AS rank, student
FROM my_table,
(SELECT @row := 0) q
WHERE teacher = 'b'
) s
WHERE student = 'e'
Upvotes: 1
Reputation: 31643
You can do it like that:
SELECT * FROM (
SELECT @row := @row + 1 as row, t.* FROM student_table t, (SELECT @row := 0) r where t.teacher ='b'
) s where student = 'e'
Upvotes: 1