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 = <условие>)"
SELECT resource.pagetitle, resource.uri, product.id, product.price, img.url AS thumb
FROM `ms2_products` AS product
JOIN `site_content` AS resource ON resource.id = product.id
LEFT JOIN `ms2_product_files` AS img ON img.product_id = product.id
WHERE img.path LIKE "%360x270%" AND img.rank=0
AND <добавить новое условие>
ORDER BY product.id DESC
LIMIT 12
CREATE TABLE animals (
grp ENUM('fish','mammal','bird') NOT NULL,
id MEDIUMINT NOT NULL AUTO_INCREMENT,
name CHAR(30) NOT NULL,
PRIMARY KEY (grp,id)
) ENGINE=MyISAM;
INSERT INTO animals (grp,name) VALUES
('mammal','dog'),('mammal','cat'),
('bird','penguin'),('fish','lax'),('mammal','whale'),
('bird','ostrich');
SELECT * FROM animals ORDER BY grp,id;
+--------+----+---------+
| grp | id | name |
+--------+----+---------+
| fish | 1 | lax |
| mammal | 1 | dog |
| mammal | 2 | cat |
| mammal | 3 | whale |
| bird | 1 | penguin |
| bird | 2 | ostrich |
+--------+----+---------+