SELECT * FROM
table t,
(VALUES (1,'1995','TOYOTA'),(2,'5015','FIAT'),(3,'1010','BMW')) AS v(o,id,make_name)
WHERE t.id=v.id AND t.make_name=v.make_name
ORDER BY v.o
with recursive table_recursive as (
with "table" as (
select *
from (
values('x','a'),
('a','b'),
('b','c'),
('c','d'),
('n','k'),
('k','l')
) as _(main,"cross")
)
select *, t.main || ' -> ' || t."cross" as "path"
from "table" as t
union
select t_r.main, t."cross", t_r."path" || ' -> ' || t."cross" as "path"
from table_recursive t_r
join "table" t on t.main = t_r."cross"
)
select t_r.*
from table_recursive t_r
where
t_r."main" not in (select "cross" from table_recursive)
and t_r."cross" not in (select "main" from table_recursive)
select prt.ball
from price_ratings prt
where prt.type_name = 'price_items'
union
select prt.ball
from price_ratings prt
left join price_items pr
on pr.price_id = prt.type_id
left join price_ratings pp
on pp.type_id = pr.id
and pp.type_name = 'price_items'
where prt.type_name = 'price'
and pp.ball is null
select isnull(prt.ball, pri.ball)
from price_items pi
left join price_ratings prt
on prt.type_id = pi.id
and prt.type_name = 'price_items'
left join price_ratings pri
on pri.type_id = pi.price_id
and pri.type_name = 'price'
SELECT `r`.`ball`
FROM (
(SELECT `ball`, 0 AS `order`
FROM `ratings`
WHERE `type_id` = :priceItemsId
AND `type_name` = 'price_items')
UNION (SELECT `r`.`ball` AS `ball`, 1 AS `order`
FROM `price_items` AS `i`
JOIN `ratings` AS `r`
ON `i`.`id` = :priceItemsId
AND `r`.`type_id` = `i`.`price_id`
AND `r`.`type_name` = `price`)
) AS `r`
ORDER BY `r`.`order`
LIMIT 1