Mysql多次选择同一行

时间:2018-03-22 11:33:55

标签: mysql

以下所有人都给我的MySQL查询。它选择id第12行两次。我已经按功能使用了组,但仍然选择了同一行两次如何解决此问题?任何人都可以告诉我为什么会发生这种情况我该如何解决这个问题?

MySQL的:

SELECT    `item`.`id`, 
          `item`.`serial`, 
          `item`.`english_name`, ( 
          CASE 
                    WHEN `user_users`.`rate_group` = 'A' THEN `item`.`a` 
                    WHEN `user_users`.`rate_group` = 'B' THEN `item`.`b` 
                    WHEN `user_users`.`rate_group` = 'C' THEN `item`.`c` 
                    WHEN `user_users`.`rate_group` = 'D' THEN `item`.`d` 
                    ELSE 0 
          END) AS rate, 
          `item`.`mrp_rate`, 
          group_concat(DISTINCT ifnull(concat('https://www.vsss.co.in/Admin/uploads/', `item`.`serial`, '/', item_image.preview), concat('https://upload.wikimedia.org/wikipedia/commons/thumb/a/ac/No_image_available.svg/600px-No_image_available.svg.png'))) AS `image`, 
          ifnull(concat('<input type='text' name='quantity' value='', `cart`.`Quantity`, ''>'), concat('<input type='text' name='quantity' placeholder='quantity'>'))                                                                                           AS quantiy, (
          CASE 
                    WHEN `user_users`.`social` = 'True' THEN concat('<a href="https://www.facebook.com/sharer/sharer.php?u=https://www.vsss.co.in/Detail/view/', `item`.`id`, '" target="_blank" ><button class="btn btn-primary icon" type="button"> <i class="fa fa-facebook-official"></i> </button></a>') 
                    ELSE '' 
          END) AS facebook, ( 
          CASE 
                    WHEN `user_users`.`social` = 'True' THEN concat('<a href="whatsapp://send?text=https://www.vsss.co.in/Detail/view/', `item`.`id`, ' " target="_blank" class="whatsapp" ><button class="btn btn-primary icon" type="button"> <i class="fa fa-whatsapp"></i> </button></a>') 
                    ELSE '' 
          END) AS whatsapp, 
          group_concat(DISTINCT ( 
          CASE 
                    WHEN `base_unit`.`id` = `unit`.`id` THEN concat('<option value='', `unit`.`ID`, '' data-unit='1' >', `unit`.`NAME`, '</option>') 
                    WHEN `cart`.`unit` = `unit`.`id` THEN concat('<option value='', `unit`.`ID`, '' data-unit='', `item_unit`.`Value`, '' selected >', `unit`.`NAME`, ' (', `item_unit`.`value`, ' ', `base_unit`.`NAME`, ')</option>') 
                    ELSE concat('<option value='', `unit`.`ID`, '' data-unit='', `item_unit`.`Value`, ''>', `unit`.`NAME`, ' (', `item_unit`.`value`, ' ', `base_unit`.`NAME`, ')</option>') 
          END) ORDER BY `unit`.`id` = `base_unit`.`id` DESC)                                                                                                                                                                                                        AS OPTION,
          ifnull(concat('<button class='btn btn-danger icon remove_from_cart' type='button' data-item='', `cart`.`Item`, ''> <i class='fa fa-shopping-cart'></i> </button>'), concat('<button class='btn btn-PRIMARY icon add_to_cart' type='button' data-item='', `item`.`ID`, ''> <i class='fa fa-shopping-cart'></i> </button>')) AS button 
FROM      `item` 
LEFT JOIN `item_unit` 
ON        `item_unit`.`item` = `item`.`id` 
LEFT JOIN `unit` 
ON        `unit`.`id` = `item_unit`.`unit` 
LEFT JOIN `unit` AS `base_unit` 
ON        `base_unit`.`id` = `item`.`base_unit` 
LEFT JOIN `item_image` 
ON        `item_image`.`item` = `item`.`id` 
LEFT JOIN `item_category` 
ON        `item_category`.`item` = `item`.`id` 
LEFT JOIN `item_sub_category` 
ON        `item_sub_category`.`item` = `item`.`id` 
LEFT JOIN `user_users` 
ON        `user_users`.`id` = 60 
LEFT JOIN `cart` 
ON        `cart`.`item` = `item`.`id` 
AND       `cart`.`USER` = 60 
WHERE     `item_sub_category`.`sub_category` IN('65') 
AND       `item`.`id` NOT                    IN('7') 
GROUP BY  `item`.`id` limit 4

0 个答案:

没有答案