V
V
Vitaly2018-06-06 19:16:50
SQL
Vitaly, 2018-06-06 19:16:50

Double query to database?

Good day. Faced the problem of making a double request to the database.
There is a table with this structure
id | id_deals | name | value
1 | 2 | user_id_email | [email protected]
2 | 2 | person_id_phone | 123456789
I need to select unique id_deals where value = [email protected] and value = 123456789
when I execute such a request I get an empty result

SELECT DISTINCT `id_deals` FROM `deals` WHERE deals.value = '[email protected]' AND deals.value = '123456789'

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
d-stream, 2018-06-06
@d-stream

I read the condition in the request: "select those people who are both a boy and a girl")
There is no deals.value in nature such that it is both '[email protected]' AND '123456789'
ps from the army "stop there and come here ")

R
Ruslan., 2018-06-06
@LaRN

It didn't work because of the AND condition, you can try like this:

SELECT DISTINCT d1.id_deals
   FROM deals d1
  INNER JOIN deals d2
                ON d2.id_deals = d1.id_deals
               AND d2.values   =‘123456789WHERE d1.value = '[email protected]'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question