N
N
Nikolaymac2017-06-08 17:09:45
MySQL
Nikolaymac, 2017-06-08 17:09:45

How to make a selection based on two conditions of one field?

9b82ca37e82b4edc9e2c2b779f9ba37f.png
There is such a table ...
you need to get all id_users that were at the point id_ap = 1 and at id_ap = 118 with one query
separately WHERE id_ap= 1 - 366 lines
WHERE id_ap = 118 - 1120 lines
made such a request ... but I don’t understand a little it
displays 308 lines ... that is, it counts only those who were at 1 by 118, but it is necessary that everyone take
SELECT vizits.id_user, id_ap FROM vizits WHERE id_ap IN (1,118) GROUP BY id_user HAVING COUNT(id_ap)=2

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Anton, 2017-06-08
@Nikolaymac

if both on that and on that - then HAVING COUNT(DISTINCT id_ap) = 2, if on any - then generally remove having

E
Eugene, 2017-06-08
@Flashter

If I understand correctly what you want, then notWHERE id_ap IN (1,118)
WHERE id_ap = '1' OR id_ap = '118')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question