Google Answers Logo
View Question
 
Q: mysql if else statement ( No Answer,   5 Comments )
Question  
Subject: mysql if else statement
Category: Computers > Programming
Asked by: stephen67-ga
List Price: $2.00
Posted: 21 Mar 2006 19:39 PST
Expires: 20 Apr 2006 20:39 PDT
Question ID: 710350
mysql if else statement

I am searching for a simple query that needs to be done in one line
that contains the following results

select f1, f2, f3, f4 from t1 where f5=Kiosk' from t1;
select f1, f2, f3, f6 from t1 where f5='Store' from t1;
I was looking at something close to 

if f5='Kiosk' 
then
select f1, f2, f3, f4 from t1 where f5=Kiosk' from t1;
else
select f1, f2, f3, f6 from t1 where f5='Store' from t1;

but I cant seem to quite get it right

Clarification of Question by stephen67-ga on 30 Mar 2006 17:06 PST
mysql> use store_data
Database changed
mysql> select Store_Name, City case Location_Type when 'Kiosk' then
Location_Type when 'CC Kiosk' then State end from stores_new;
ERROR 1064 (42000): You have an error in your SQL syntax; check the
manual that corresponds to your MySQL server version for the right
syntax to use near 'case Location_Type when 'Kiosk' then Location_Type
when 'CC Kiosk' then State en' at line 1
Answer  
There is no answer at this time.

Comments  
Subject: Re: mysql if else statement
From: daemon_byte-ga on 22 Mar 2006 08:09 PST
 
you dont mention and end if 

if f5='Kiosk' then
select f1, f2, f3, f4 from t1 where f5=Kiosk' from t1;
else
select f1, f2, f3, f6 from t1 where f5='Store' from t1;
END IF;
Subject: Re: mysql if else statement
From: stephen67-ga on 22 Mar 2006 12:54 PST
 
If this the entier statement?  

Cause I am not getting it to work

mysql> use store_data
Database changed
mysql> select Location_Type from stores_new
    -> if Location_Type='Kiosk'
    -> then
    -> select Store_Name, Location_Type where Location_Type='Kiosk'
from stores_new
    -> else
    -> select Store_Name, Location_Type from stores_new where
Location_Type='Kiosk CC' from stores_new
    -> end if;
ERROR 1064 (42000): You have an error in your SQL syntax; check the
manual that corresponds to your MySQL server version for the right
syntax to use near 'if Location_Type='Kiosk'
then
select Store_Name where Location_Type='Kiosk' from' at line 2
mysql>
Subject: Re: mysql if else statement
From: nelson-ga on 22 Mar 2006 19:51 PST
 
select f1, f2, f3, case f5 when 'Kiosk' then f4 when 'Store' then f6 end from t1
Subject: Re: mysql if else statement
From: stephen67-ga on 30 Mar 2006 17:07 PST
 
mysql> use store_data
Database changed
mysql> select Store_Name, City case Location_Type when 'Kiosk' then
Location_Type when 'CC Kiosk' then State end from stores_new;
ERROR 1064 (42000): You have an error in your SQL syntax; check the
manual that corresponds to your MySQL server version for the right
syntax to use near 'case Location_Type when 'Kiosk' then Location_Type
when 'CC Kiosk' then State en' at line 1
Subject: Re: mysql if else statement
From: rafaeljusi-ga on 17 Apr 2006 12:35 PDT
 
try: select f1, f2, f3, if(f5='Kiosk',f4,f6) from t1

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy