Mysql case select multiple columns1/1/2024 ![]() ![]() There is no defined maximum for the number of WHEN conditions you can have within a CASE WHEN statement. Time to complete a query can be a problem. ![]() Note: you do not have to show all of the columns, or any columns besides the CASE column in the output. SELECT ( optional : any desired columns ), CASE WHEN ( condition ) THEN ( desired output ) WHEN ( other condition ) THEN ( desired output ) ELSE ( desired output ) END AS ( descriptive header for the output column ) FROM ( appropriate table ) In the example we see this done with ELSE City which puts LA unchanged in the new column Syntax NOTE: If you put the column name after THEN or ELSE it will put the value from the original column into the newly created column. AS: Used to set a specific name for the returned CASE column.END: Indicates the end of the CASE loop.If no ELSE statement is present and all WHEN conditions are false, the returned value will be NULL.ELSE: catches all of the entries that were not true for any of the WHEN conditions. ![]()
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |