Программирование сайтов
Stebenkov
19 Май в 07:09

Представления в базе данных MySQL

Например, удобно сделать для поиска по нескольким таблицам.

CREATE OR REPLACE VIEW tbl_view_search AS
SELECT CONCAT('post_', id) AS id, id AS source_id, text, CONCAT('/', url) AS url, title, logo AS img, NULL AS price FROM posts UNION 
SELECT CONCAT('product_', id) AS id, id AS source_id, text, CONCAT('/path/to/', url) AS url, title, img, price FROM products;