473,385 Members | 1,317 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

MySQL Select Case

I'm trying to get the venue in the 'List' column when in contains a
value. But if the venue Is Null then place the event in the 'List'

SELECT
CASE
WHEN event Is Null THEN venue
Else
event
End as 'List'
,DATE_FORMAT(fld_date, '%M') as Monthly
From na_statistics


Jun 12 '06 #1
2 6749

vn****@hotmail.com wrote:
I'm trying to get the venue in the 'List' column when in contains a
value. But if the venue Is Null then place the event in the 'List'

SELECT
CASE
WHEN event Is Null THEN venue
Else
event
End as 'List'
,DATE_FORMAT(fld_date, '%M') as Monthly
From na_statistics


SELECT
COALESCE("event", "venue") AS "list",
DATE_FORMAT("date", '%M') AS "monthly"
FROM "my_namespace"."na_statistics";

So why not use the COALESCE function? Is this not exactly what it is
for? You can have as many values as you want and the database with use
the first non-null value specified. But that said I see nothing wrong
with your syntax for CASE except that the logic does not match your
explaination (you say you want "venue" if available and "event" only
when "venue" isn't; but you are instead checking "event" for null and
using "venue" only then). Also, IF/THEN could have done the same work
as well. Or "IFNULL" (similar to COALESCE but accepting exactly two
parameters).

And just an aside: I'm not sure about MySQL but under PostgreSQL you
_can_ use reserved words in field names as long as they are surrounded
by double-quotes. So fld_date can become just "date" which I think is a
bit more elegant. Besides that I always surround my identifiers in
quotes out of habit. :o) The only thing with that is that when you put
identifiers in quotes IIRC they become case sensitive so I also make it
a habit to use lower case for identifiers all the time. And I guess
other than that it's a good idea to fully qualify table names with the
appropriate namespace. In MySQL that means always specifying the
database in the FROM/JOIN clauses. In PostgreSQL that means always
specifying the schema there.

-Robert

Jun 12 '06 #2
vncntj wrote:
if the venue Is Null [...] WHEN event Is Null


??

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact

Jun 12 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Gordon | last post by:
I have 2 tables t and t1. In this case, t1 is a copy of t. I want to delete rows from t1 based on criteria on the t table and a relationship between t ad t1 (in this case the id column). In the...
0
by: Lenz Grimmer | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, MySQL 4.0.14, a new version of the popular Open Source/Free Software Database, has been released. It is now available in source and binary...
0
by: Mike Chirico | last post by:
Interesting Things to Know about MySQL Mike Chirico (mchirico@users.sourceforge.net) Copyright (GPU Free Documentation License) 2004 Last Updated: Mon Jun 7 10:37:28 EDT 2004 The latest...
2
by: sunny076 | last post by:
Hi, I am confused with the syntax for NOT in MYSQL where clause and wonder if an expert in MYSQL can enlighten me. There are possibly two places NOT can go in: select * from employee_data...
1
by: jlee | last post by:
I'm pretty much a newbie on mysql, and I need some help. I am running mysql Ver 12.22 Distrib 4.0.24, for portbld-freebsd5.4 (i386) on a server hosting an active website. The site's developer...
2
by: m.k.ball | last post by:
Thanks Rich - that's great. Before I found this group, I thought I had a reasonable understanding of SQL (well, MySQL's implementation of it, at least) but the truth is there are great chunks that...
8
by: Fred | last post by:
Hello, Our website is currently developed in ASP/Mysql 4. The dedicated servers on which it is currently hosted arrive at saturation. Here is their configuration: - 1 server PIV 2,8Ghz 1GB...
1
by: mejames | last post by:
I am using VB.NET 2003, MYSQL database and Crystal Reports. I am able to generate 1 set of reports using the following code: Imports MySql.Data.MySqlClient Imports...
3
by: janetopps | last post by:
I have a news website, with asp pages, which was on Access, and i upgraded to MySQL, i used Bullzip to transfer the data. It had about 1000 pages, which im now able to pull up on the public side. Im...
1
ssnaik84
by: ssnaik84 | last post by:
Hi Guys, Last year I got a chance to work with R&D team, which was working on DB scripts conversion.. Though there is migration tool available, it converts only tables and constraints.. Rest of...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.