Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed last month.
Improve this question
Hello In my application I wanted to show the ads to the users depending on the audience selected by the advertiser. at the moment I am saving gender to each user in the user database. The ads work best if the user selects gender male or female. But I don't know how I can modify the query if the user selected all as an audience.
I have two tables. Promotion and audience. This is how I am querying at the moment
SELECT p.id
, v.id
, a.id
, a.user_id
, a.name
, a.min_age
, a.max_age
, a.gender
, a.created
FROM promotion p
LEFT
JOIN video v
ON v.id = p.video_id
LEFT
JOIN audience a
ON a.id = p.audience_id
WHERE p.user_id != 17
AND a.gender = 'Male'
what I am intended to do is that if the gender value in the Audience table is saved as all then It shouldn't check male or female in the query. It should get all the records irrespective of the fact the user is male or female
# Answer 1
Are you looking for something like this?
WHERE ....
AND `Audience`.`gender` IN ('All', ?)
The question mark represents the parameter to the query, that corresponds to the user's gender. It may take value 'Male' or 'Female'. If audiences stored gender is 'All', the condition always matches, regardless of the parameter given.