MySQL Forums
Forum List  »  MySQL Query Browser

SELECT ... SELECT IN MYSQL
Posted by: Aravind Kumar
Date: June 11, 2013 07:46AM

I am trying to write a query for mysql (Search Module) where I am facing difficulties because of the select operation to be carried out inside same table.

My Query:

(SELECT * FROM user WHERE `user_name` like '%TOM%' OR `user_name` like '%AN%'
and `login_datetime` BETWEEN '2013-01-01 00:00:00' and '2013-02-31 23:59:59')
OR
(SELECT * FROM user WHERE `user_name` like '%PHP%' OR `user_name` like '%BA%'
and `login_datetime` BETWEEN '2013-02-01 00:00:00' and '2013-03-31 23:59:59')
AND
(SELECT * FROM user WHERE `user_name` like '%SUN%' OR `user_name` like '%MOON%'
and `login_datetime` BETWEEN '2013-03-01 00:00:00' and '2013-04-31 23:59:59')
NAND
(SELECT * FROM user WHERE `user_name` like '%RAJ%' OR `user_name` like '%MUTH%'
and `login_datetime` BETWEEN '2013-04-01 00:00:00' and '2013-06-31 23:59:59')
NOR
(SELECT * FROM user WHERE `user_name` like '%BAG%' OR `user_name` like '%LAP%'
and `login_datetime` BETWEEN '2013-05-01 00:00:00' and '2013-07-31 23:59:59')
The above mentioned query is my scenario.. Where this cannot be changed, I am trying to write a Query for this.

Note:
The above query execute in a single table.
OR, NAND, NOR, AND operation can be inter-changed with according to the situation.
It depends with the user, how he needs to search.
I tried many ways to achieve the logic but I am facing issues in all phases.

Options: ReplyQuote


Subject
Written By
Posted
SELECT ... SELECT IN MYSQL
June 11, 2013 07:46AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.