how to query from a literal list : select * from ('a', 'b', 'c')
mysql, sql
Solution
Use UNION
select tbl1.*, details.*
from (select 'a'as id
union
select 'b' as id
union
select 'c' as id
union
...300) as tbl1
left join details
on
details.id=tbl1.id
See this Fiidle Logic
Instead of using Subquery, you can first create a table `tbl1` as
create table tbl1
(
id varchar(1)
)
insert into tbl1
select 'a' as id
union
select 'b' as id
union
select 'c' as id
....300
now you can use table tbl1 for `join`
select tbl1.*, details.*
from 'tbl1'
left join details
on
details.id=tbl1.id
Problem
i'm using `mysql 5.5`, here is a left join query with a `literal` list: ``` select tbl1.*, details.* from ('a', 'b', 'c'... 300+ elements) as 'tbl1' left join details on details.id=tbl1.id ``` but it doesn't work! `You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''a','b')' at line 1` how to make this `list` as a table??