How do write IF ELSE statement in a MySQL query

0 votes

How do I write an IF ELSE statement in a MySQL query?

Something like this:

mysql_query("...(irrelevant code).. IF(action==2&&state==0){state=1}");


Then down in my array I should be able to do this:

$row['state'] 
//this should equal 1, the query should not change anything in the database, 
//just the variable for returning the information

Feb 18, 2022 in Web Development by Rahul
• 9,670 points
417 views

1 answer to this question.

0 votes

You probably want to use a CASE expression which looks like this:

SELECT col1, col2, (case when (action = 2 and state = 0) 
THEN 
            1 
ELSE 
            0 
END)
as state from tbl1;

answered Feb 18, 2022 by Aditya
• 7,680 points

Related Questions In Web Development

0 votes
0 answers

If/else else if in Jquery for a condition

I am having a set of text ...READ MORE

Jul 1, 2022 in Web Development by gaurav
• 23,260 points
2,304 views
0 votes
1 answer

Do all HTML tags come in a pair?

HTML tags can be of two types: 1.Paired ...READ MORE

answered Jan 16, 2020 in Web Development by anonymous
3,220 views
0 votes
2 answers

How to verify links that open in a new tab in phpUnit?

Hey @Marium, What do you mean by "the ...READ MORE

answered Dec 14, 2020 in Web Development by Gitika
• 65,910 points
1,027 views
0 votes
0 answers

How to add a link in Jquery PrettyPhoto to download the image

I am using Jquery PrettyPhoto to have ...READ MORE

Jun 29, 2022 in Web Development by gaurav
• 23,260 points
646 views
0 votes
0 answers

How to show message in model body if bootstrap model have no data in jquery

I'm trying to display a text message ...READ MORE

Jul 29, 2022 in Web Development by gaurav
• 23,260 points
591 views
0 votes
0 answers

Using if(isset($_POST['submit'])) to not display echo when script is open is not working

I'm running into a small issue with ...READ MORE

Aug 1, 2022 in PHP by Kithuzzz
• 38,010 points
2,272 views
0 votes
1 answer

Want a command to be executed in Salt only if a directory is empty

You should consider using this inside your ...READ MORE

answered Jun 12, 2018 in DevOps Tools by Damon Salvatore
• 5,980 points
1,480 views
0 votes
1 answer

Creating A New MySQL User In Amazon RDS Environment

AWS RDS security groups documentation (a common ...READ MORE

answered Jul 18, 2018 in AWS by Priyaj
• 58,090 points
1,769 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP