Примеры таблиц для запроса:
Таблица заказов — cms_shop_cart
---+----------------------+---------+------------+-----+------------+-------+------------ 1 | eeb39d6c6c6836c75a73 | 12 | 001-4 | 1 | 2015-02-02 | NULL | NULL 4 | 78bfef9afbea7b2910fb | 13 | 002-4 | 1 | 2015-02-02 | NULL | NULL
Таблица товаров — cms_shop_items
id | category_id | art_no | title | price |is_digital | seolink | qty | filename | filename_orig ---+-------------+--------+-------+-------+-----------+---------+-----+------------------------- 12 | 27 | 001 | Чай А | 100 | 0 | dir1 | 0 | 13 | 27 | 002 | Чай Б | 150 | 0 | dir1 | 0 |
Таблица характеристик — cms_shop_chars_val
item_id | char_id | val ---------------------------- 12 | 28 | 100 12 | 29 | Черный 12 | 30 | Карт 13 | 28 | 100 13 | 29 | Зеленый 13 | 30 | Карт
Сейчас выборка идет из двух таблиц и запрос выгдялит так
$base_sql = "SELECT items.title as title, items.price as price, items.art_no as art_no, items.seolink as seolink, items.qty as qty, cart.qty as cart_qty, cart.item_id as item_id, cart.id as cart_id, cart.chars as chars, items.is_digital as is_digital, items.filename as filename_item, items.filename_orig as filename_orig, items.category_id as category_id FROM cms_shop_cart cart, cms_shop_items items, WHERE cart.session_id = '{$session_id}' AND (cart.var_art_no = '' OR cart.var_art_no = '0') AND cart.item_id = items.id";
Пытаюсь прилипить еще одну таблицу чтобы выводились и характеристики
$base_sql = "SELECT items.title as title, items.price as price, items.art_no as art_no, items.seolink as seolink, items.qty as qty, cart.qty as cart_qty, cart.item_id as item_id, cart.id as cart_id, cart.chars as chars, items.is_digital as is_digital, items.filename as filename_item, items.filename_orig as filename_orig, items.category_id as category_id, val.val as value FROM cms_shop_cart cart, cms_shop_items items LEFT JOIN cms_shop_chars_val val ON val.char_id = 29 AND val.item_id = cart.id WHERE cart.session_id = '{$session_id}' AND (cart.var_art_no = '' OR cart.var_art_no = '0') AND cart.item_id = items.id";
Подскажите что делаю не так? Где в запросе ошибка?