Answer the question
In order to leave comments, you need to log in
How to validate two fields?
DB: sqlfiddle.com/#!9/0f9a0/1
Task: find prisoners who are in the same cell and are on the same case.
I was only able to implement the search for prisoners who are involved in one case.
SELECT K.*
FROM Klienti AS K
WHERE K.k_nomer_dela IN (
SELECT Kk.k_nomer_dela
FROM Klienti AS Kk
GROUP BY Kk.k_nomer_dela
HAVING COUNT(*) > 1
)
SELECT K.*
FROM Klienti AS K
WHERE K.nomer_kameri IN (
SELECT Kk.nomer_kameri
FROM Klienti AS Kk
GROUP BY Kk.nomer_kameri
HAVING COUNT(*) > 1
)
Answer the question
In order to leave comments, you need to log in
What if we just put both conditions in the same query and AND between them?
SELECT K.*
FROM Klienti AS K
WHERE K.k_nomer_dela IN (
SELECT Kk.k_nomer_dela
FROM Klienti AS Kk
GROUP BY Kk.k_nomer_dela
HAVING COUNT(*) > 1
)
AND
K.nomer_kameri IN (
SELECT Kk.nomer_kameri
FROM Klienti AS Kk
GROUP BY Kk.nomer_kameri
HAVING COUNT(*) > 1
)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question