Trying to write this mysql query

I am trying to get data from a table with this query

SELECT DATE( mdate ) AS mdt, u_id, d_id, COUNT(*) AS ttp, '3', a_id
FROM ar_typ
WHERE u_id >  '0'
AND a_id <> u_id
AND a_id <>  '0'
AND c_id =  '2020'
GROUP BY mdt, c_id
ORDER BY mdt ASC, u_id ASC, ttp ASC, c_id ASC

My PHP code works fine but having problem with MySQL. Because i know the u_id value in PHP. Let’s say u_id is ’10’. So u_id and a_id can not be 10. However in this MySQL code it can. Actually in PHP code instead of using u_id > '0' i am using u_id = '10' and because i want to get all data instead of one specific one, i am getting all data greater than zero.

I know this is working as expected but i just need this query return empty.

If you wonder why i am trying to get empty data, here is my actual code:

SELECT DATE( mdate ) AS mdt, u_id, d_id, COUNT(*) AS ttp, '3', a_id
FROM ar_typ
WHERE u_id >  '0'
AND a_id <> u_id
AND a_id <> '0'
GROUP BY mdt, c_id
ORDER BY mdt ASC, u_id ASC, ttp ASC, c_id ASC

I have just removed AND c_id = '2020' part. It is a bit hard to explain but i hope i did.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s