select a.data, b.another_data
from block as a join block_one as b on (a.main_block_id=b.main_block_id)
where a.type = 'one'
union all
select a.data, b.third_data
from block as a join block_two as b on (a.main_block_id=b.main_block_id)
where a.type = 'two'
select distinct a.data,
(case when a.type='one' then b.another_data else c.third_data end) as some_data
from block as a left join block_one as b on (a.type = 'one' and a.main_block_id=b.main_block_id)
left join block_two as c on (a.type = 'two' and a.main_block_id=c.main_block_id)
SELECT `articles`.`id`, count(user_idea_likes.idea_id) AS likes,
count(subscribed_user_articles.article_id) AS subscribed
FROM `articles`
LEFT JOIN `user_article_likes` ON `user_article_likes`.`article_id` = `articles`.`id`
LEFT JOIN `subscribed_user_articles` ON `subscribed_user_articles`.`article_id` = `articles`.`id`
GROUP BY `articles`.`id`
SELECT *
FROM `poll`
INNER JOIN poll_answer ON poll.id = poll_answer.poll_id
INNER JOIN poll_result ON poll_answer.id = poll_result.poll_answer_id
WHERE CURDATE() BETWEEN poll.date_begin AND poll.date_end
AND poll_result.vote_ip ="222"
SELECT *
FROM `poll` as b
WHERE NOT EXISTS (SELECT poll.id
FROM `poll`
INNER JOIN poll_answer ON poll.id = poll_answer.poll_id
INNER JOIN poll_result ON poll_answer.id = poll_result.poll_answer_id
WHERE CURDATE() BETWEEN poll.date_begin AND poll.date_end
AND poll_result.vote_ip ="222"
AND b.id = poll.id)
select distinct po.product_id,
(case when po.region_id in (1,2,3,4) then order_id else null end) as order_id,
(case when po.region_id in (1,2,3,4) then p.product_name else null end) as product_name,
(case when po.region_id in (1,2,3,4) then po.order_date else null end) as order_date,
region_id
from products_orders po
left join products p
on p.id = po.product_id
where
po.product_id = 100
select a.*
from `article` as a
join `articleTag` AS aT ON(aT.articleID = a.id)
join `Tags` as t ON (aT.tagID = t.id)
where t.alias = <условие>
Есть ли способ, чтобы не меняя связи сделать поиск не по tagID(в промежуточной таблице) а по alias? Или как-то конвертировать запросом выше из alias в id тега?
"SELECT * FROM `articleTag` AS aT LEFT JOIN `article` AS a ON(aT.articleID = a.id)
WHERE aT.tagID in (select aa.id from `Tags` as aa where aa.alias = <условие>)"