MySQL Select multiple columns as one

Hi, I have a table with the following fields in:

image1
image2
image3

I want to select them all as one column and loop through them all populating a single listbox with them.

I tried combining them all using syntax like

"SELECT (image1, image2, image3) AS image FROM tblimages"

but this didn't work, it just gave me an error. I also tried:

"SELECT image (image1, image2, image3) FROM tblimages"

but this also gave me an error. Lastly I tried

"SELECT image1 AS image, image AS image, image3 AS image FROM tblimages"

This didn't give me an error but it stil returned 3 seperate columns but all with the same name.

I know this is going to be really simple isn't it! Please help!
LVL 1
m175400Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hernst42Commented:
what do you mean by one column? You can use concat.

SELECT  concat(image1, image2, image3) AS image FROM tblimages

If you want to get those three columns as three seperate rows you will need multiple joins and if -conditions in your query and the query will be come very complicated.
0
m175400Author Commented:
I want all the columns to be returns as if they're just one column, one record after the other. I don't want to actually combine the values into new values, I want all the records from all the columns and to be able to page through all the rows sequentially just as if I'd done

SELECT image1 FROM tblImages

Make sense now?

Thanks!
0
hernst42Commented:
If you want to do that, The only solution I can think of is having a second table (ctable) only a id-column with three rows where id is 1,2 and 3
CREATE TABLE ctable (id int);
insert INTO ctable VALUES (1), (2), (3);

Then use this select:
Select if(b.id=1, image1,if(b.id=2, image2, image3)) FROM  tblimages a,  ctable b

Ther migth be a solution to do it with one tbale, but that is very complicated and beyond my knowledge

0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

virmaiorCommented:
or alternately use the union syntax:

( SELECT image1 as image FROM tblimages)
UNION
(SELECT image2 as image FROM tblimages)
UNION
(SELECT image3 as image FROM tblimages)

(which is the right way of saying: SELECT image1 AS image, image AS image, image3 AS image FROM tblimages)

problematically this will require a version of MySQL of 4.0+
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
m175400Author Commented:
Many thanks! That seems to work! One weird thing though - I get one extra record with a null value retrieved? Any ideas?
0
m175400Author Commented:
Ah nevermind, sorted it.

Thanks again guys!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
MySQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.