MySQL Forums
Forum List  »  Newbie

Re: Run one of the two sql queries depending on result of third query.
Posted by: Pramod Patki
Date: October 02, 2015 10:49AM

I tried using IF but getting error as below:

mysql> SELECT IF(((select distinct role from table_name_1 where user = 'user1') = 'admin'),(SELECT name, display, good_high, critical_low, warning_low, warning_high FROM table_name_1 WHERE user = 'user1' AND sub_name = ''),(SELECT name, display, good_high, critical_low, warning_low, warning_high FROM table_name_1 WHERE user = 'user1' AND sub_name = '' AND name != 'some_name'));
ERROR 1241 (21000): Operand should contain 1 column(s)


mysql> SELECT IF(((select role from table_name_1 where user = 'user1' limit 1) = 'admin'),(SELECT name, display, good_high, critical_low, warning_low, warning_high FROM table_name_1 WHERE user = 'user1' AND sub_name = ''),(SELECT name, display, good_high, critical_low, warning_low, warning_high FROM table_name_1 WHERE user = 'user1' AND sub_name = '' AND name != 'some_name'));
ERROR 1241 (21000): Operand should contain 1 column(s)
mysql>

Options: ReplyQuote


Subject
Written By
Posted
Re: Run one of the two sql queries depending on result of third query.
October 02, 2015 10:49AM


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.