* Russell Michell > I was wondering if it's possible to perform an "elseif" in SQL Using MySQL > 3.23.49-log running on Debian Linux?
It sure is. See below. > My System: > ---------- > > * MySQL 3.23.49-log > * Debian Linux > * PHP 4.2.1 > > The Logic: > ---------- > > IF condition1 - THEN query column1. > ELSEIF condition2 - THEN query column2. > ELSE condition3 query column2. > > The SQL: (more pseudo code than anything else) > ---------------------------------------------- > > SELECT a,b,c > FROM companies > WHERE > IF(subscription AND no module , bitwise-data & column1 > ELSEIF no subscription AND no module , bitwise-data & column2 , > ELSE bitwise-data & column2) > ORDER BY a"; It seems condition 2 and 3 are the same? typo? If they are the same,you don't need ELSEIF, just a normal IF-ELSE: IF(subscription AND NOT module,bitwise-data & column1,bitwise-data & column2). > The "bitwise-data" is an integer bit from a URL Query String, it > needs to be compared with one of two columns (column1 or column2) > but which column is used depends upon whether a company has a > subscription or not. Making column d dependant on subscription and module: SELECT a,b,c, IF(subscription AND NOT module, bitwise-data & column1, IF(NOT subscription AND NOT module, bitwise-data & column2, bitwise-data & column2)) AS d FROM companies WHERE <whatever> ORDER BY a The IF() function is described here: <URL: http://www.mysql.com/doc/en/Control_flow_functions.html#IDX1161 > -- Roger -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]