-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
> I have a select statement that selects two string (text) fields. In some > cases, the first of them may be NULL. In this case, I would like the > second field to be selected instead. It is also possible that in rare > cases that the second string may be NULL, in which case it should just > return NULL. > > Ex: > I have a table similar to: > Key | str1 | str2 > 0 | "str1" | "anotherstr" > 1 | NULL | "string" > 2 | NULL | NULL > > > I would like the select statement to return: > Key | Str > 0 | "str1" > 1 | "string" > 2 | NULL > > How possible is this? You could do a SELECT key, CASE WHEN str1 = NULL THEN str2 ELSE str1 END as str FROM ...; or maybe also a SELECT key, IFNULL(str1, str2) AS str FROM ...; should work. (both not tested) -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.3 (GNU/Linux) iQEVAwUBP5t31ZFyPD7t0rMPAQJZeAgAkwgaDJeqOZr/V8FJUSPG3XuYESZnMvbJ 2vOjtDWMRyRS5ppU0GqtUUDhLBlvRbmYzBnrJwiqreQlXqc7e1o5lCy6kZVK25+H I+1mSd3ywiqZ3rW2dy9Bqe8QJ+t0rUjLDzUz5+eRbXdRSf/Bn0EJVzphBTVXoGpU kjnr8JGajjYWrmwwVdPjI/63iBiLpxMDL6iIk6mQpQtnv1To4HPj/qWeO78107GW gbo9ZdoJ/trHRn49/NsWYXvs5LSMex8B0Rp9TZLhndmfyMnL6im1NtvQAohYwDEi h28udg/tvE9RIgHc+zxv6CROWS2uBES8RBk0P/HxL68Nk4i3VjYl8Q== =jxdk -----END PGP SIGNATURE----- -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]