I have written following select query which returns the required records.I know how to code this in PHP. I am wondering if it is possible in one single select mysql query
WHERE email = 'firstname.lastname@example.org'
AND password = 'password'
then current date
If expiry_id='0' THEN
check annual_end_date column
If annual_end_date is less then the current date
check pay_end_date column in subscription table
If pay_end_date is less then the current date then show records
You can add something like this to your query...
AND ( ( expiry_id='0' AND annual_end_date < DATE(NOW()) ) OR ( expiry_id<>'0' AND EXISTS ( SELECT 1 FROM subscription s WHERE s.user_id = Users.user_id -- ? AND s.pay_end_date < DATE(NOW()) ) ) )
The specification says to check the "subscription table", but no indication is given about the relationship between
Users. The subquery is based on a guess about the foreign key column in subscription, and the referenced column in