S
S
sidor_tank2019-07-28 20:42:54
Java
sidor_tank, 2019-07-28 20:42:54

How to create a specific request?

Hello everyone, I need to create a query that contains a subquery with a condition.
I need to make sure that if this subquery condition is not met for at least one record, then the parent record is also not selected from the database. I hope I explained it clearly, in fact it looks like this: from the request we select Map<'record1', List<'record2'>>, if at least one of record2 does not fulfill the condition, the map member should not be selected from the database.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Igor Vorotnev, 2019-07-29
@sidor_tank

Based on the assumption that it's one-to-many and dates are date you need a normal JOIN and date comparison:

SELECT * 
FROM `products`
JOIN `opportunities`
ON `opportunities`.`product_id` = `products`.`id`
WHERE `start_date` > '2019-07-01'
AND `end_date` < '2019-08-01';

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question