나는 다음과 같은 쿼리가 :Zend_db_select
$selectProducts = $db->select()
->from('products', array('products.uid AS id',
'products.title',
'products.ean',
'products.description',
'products.price',
'products.date_publish',
'publishers.name',
'GROUP_CONCAT(CONCAT (authors.first_name, \' \', authors.last_name) SEPARATOR \', \') AS authors'))
->join('publishers', 'products.uid_publisher = publishers.uid')
->join('products_authors_mm', 'products.uid = products_authors_mm.uid_product')
->join('authors', 'products_authors_mm.uid_author = authors.uid')
->group('products.uid');
$finalSelect = $db->select()
->from($selectProducts)
->where('t.title LIKE ?', '%' . $query . '%')
->orWhere('t.name LIKE ?', '%' . $query . '%')
->orWhere('t.authors LIKE ?', '%' . $query . '%');
MYSQL이 나에게 다음과 같은 오류를 제공합니다 : 나는 그런 zend_db_select
쿼리에 넣어하려고하면
SELECT *
FROM
(SELECT products.uid, products.title, products.ean, products.description, products.price, products.date_publish, publishers.name, GROUP_CONCAT(CONCAT (authors.first_name, ' ', authors.last_name) SEPARATOR ', ') AS authors
FROM products
INNER JOIN publishers
ON products.uid_publisher = publishers.uid
INNER JOIN products_authors_mm
ON products.uid = products_authors_mm.uid_product
INNER JOIN authors
ON products_authors_mm.uid_author = authors.uid
GROUP BY products.uid) AS t
WHERE title LIKE '%jerzy%' OR name LIKE '%jerzy%' OR authors LIKE '%jerzy%'
를 :
Message: SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'name'
내 $finalSelect
에코 때, 나는이 쿼리를 얻을 :
SELECT `t`.*
FROM
(SELECT `products`.`uid` AS `id`, `products`.`title`, `products`.`ean`, `products`.`description`, `products`.`price`, `products`.`date_publish`, `publishers`.`name`,
GROUP_CONCAT(CONCAT (authors.first_name, ' ', authors.last_name) SEPARATOR ', ') AS `authors`**, `publishers`.*, `products_authors_mm`.*, `authors`.***
FROM `products`
INNER JOIN `publishers` ON products.uid_publisher = publishers.uid
INNER JOIN `products_authors_mm` ON products.uid = products_authors_mm.uid_product
INNER JOIN `authors` ON products_authors_mm.uid_author = authors.uid
GROUP BY `products`.`uid`) AS `t`
WHERE (t.title LIKE '%Andrzej%') OR (t.name LIKE '%Andrzej%') OR (t.authors LIKE '%Andrzej%')
거기에서 publishers.*, products_authors_mm.*, authors.*
을 제거하면 올바르게 작동합니다.
제 질문은이 쿼리가 작동하도록 PHP 코드를 어떻게 바꿀 수 있습니까?
THX, 난이 세번째 파라미터 잊어 – vthruu