john doe
john doe

Reputation: 9690

Querying from a Hard-Coded List MySql

How can I do this? I want to query from a hard-coded list?

select (222,
333,
444,
555,
666,
777,
777,
88,
999,
099) as imageids 

Upvotes: 1

Views: 370

Answers (1)

stj
stj

Reputation: 9107

You could create multiple rows, each containing one image id:

select 222 as imageid
union select 333
union select 444
union select 555
union select 666
union select 777
union select 777
union select 88
union select 999
union select 099

or return a comma-separated string with all image ids:

select group_concat(222, 333, 444, 555, 666, 777, 88, 999, 099) as imageids

Note that a value of 099 will be returned as 99 because it will be treated as an integer. If you need to preserve leading zeros, you should use string values (i.e. "099" instead of 099).

Upvotes: 1

Related Questions