is it possible use own tuples as a source for an JOIN statement?
Here is an example of what I'm looking for:
SELECT开发者_如何学Python u.id, u.name FROM users u
INNER JOIN {{tupl1},{tupel2},{tupel3},...}
In SQL Server 2008 you use the Table Value Constructor.
declare @T table(ID int)
insert into @T values (1),(2),(3),(4),(5)
select *
from @T as T1
inner join (
values (1, 'Row 1'),
(2, 'Row 2')
) as T2(ID, Col1)
on T1.ID = T2.ID
Many dbms platforms support common table expressions.
with my_own_tuples as (
select 'value1' as column1, 'value2' as column2
union all
select 'value3', 'value4'
union all
select 'value5', 'value6'
)
select column1, column2
from my_other_table
inner join my_own_tuples on (my_own_tuples.column1 = my_other_table.column1);
PostgreSQL Common Table Expressions
MySql has some support for Tuples with comparisons and equality, although I'm struggling to find a definitive reference for this.
For example:
SELECT *
FROM table1 t1
INNER JOIN table2 t2
ON (t1.Col1, t1.Col2) = (t2.Col1, t2.Col2);
And
SELECT *
FROM table1 t1
WHERE (t1.Col1, t1.Col2) <= ('SomeValue', 1234);
SqlFiddle showing these here
精彩评论