Select distinct on Left Join for only one column

nick

I'm trying to list products that each customer bought, but if they bought the same item on different occasions, I want it to exclude it. This is what I have so far:

Select  c.field_id_33  AS email, o.order_id, Group_concat(o.entry_id) AS Products,group_concat(t.title),group_concat(t.url_title) from finn_cartthrob_order_items o  
LEFT JOIN finn_channel_data c
ON c.entry_id=o.order_id
LEFT JOIN finn_channel_titles t
ON o.entry_id=t.entry_id
GROUP BY email

This is producing:

screenshot

Basically I only need a product listed one time if they've purchased it, no matter how many times they've purchased it. How would I do this?

M Khalid Junaid

You can use DISTINCT in group_concat function,using Group_concat baware of that fact it has a default limit of 1024 characters to group them but it can be increased

Select  c.field_id_33  AS email, o.order_id, 
Group_concat(DISTINCT o.entry_id) AS Products,
group_concat(DISTINCT t.title),
group_concat(DISTINCT t.url_title)
 from finn_cartthrob_order_items o  
LEFT JOIN finn_channel_data c
ON c.entry_id=o.order_id
LEFT JOIN finn_channel_titles t
ON o.entry_id=t.entry_id
GROUP BY email

From the docs The result is truncated to the maximum length that is given by the group_concat_max_len system variable, which has a default value of 1024. The value can be set higher, although the effective maximum length of the return value is constrained by the value of max_allowed_packet. The syntax to change the value of group_concat_max_len at runtime is as follows, where val is an unsigned integer:

SET [GLOBAL | SESSION] group_concat_max_len = val;

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

MySQL DISTINCT on one column and LEFT JOIN

From Dev

SQL - select distinct only on one column

From Dev

select only distinct value from one column

From Dev

MySQL Select Distinct with Left Join?

From Dev

MySQL LEFT JOIN with DISTINCT or LIMIT. Need to LEFT JOIN only one value

From Dev

Distinct only on one column

From Dev

DISTINCT to only one column

From Dev

Select distinct for one column

From Dev

Select multiple columns with only one distinct column in sql

From Dev

MySQL LEFT JOIN only one row, ordered by column without subquery

From Dev

MySQL LEFT JOIN only one row, ordered by column without subquery

From Dev

How to left join with or operator and determined only one column that match

From Java

Postgres: Distinct but only for one column

From Dev

Postgres: Distinct but only for one column and latest one

From Dev

Postgres: Distinct but only for one column and latest one

From Dev

Distinct by Category then Join all distinct values per Category in one column

From Dev

Select only 1 distinct column - SQL

From Dev

SQL return only distinct IDs from LEFT JOIN

From Java

How to left_join() two datasets but only select specific columns from one of the datasets?

From Dev

sql - how to select multiple columns with only one distinct column from joining multiple tables

From Dev

Select multiple columns with only one distinct column in SQL Server Compact Edition

From Dev

Where clause for only one table in a left join

From Dev

why this left join returns only one record?

From Dev

Show only one result in sql LEFT JOIN

From Dev

Hide column from a left join select

From Dev

Insert distinct values only for one column

From Dev

mysql using DISTINCT for only one column

From Dev

Insert distinct values only for one column

From Dev

Select all from Table A, one column from Table B - LEFT JOIN

Related Related

  1. 1

    MySQL DISTINCT on one column and LEFT JOIN

  2. 2

    SQL - select distinct only on one column

  3. 3

    select only distinct value from one column

  4. 4

    MySQL Select Distinct with Left Join?

  5. 5

    MySQL LEFT JOIN with DISTINCT or LIMIT. Need to LEFT JOIN only one value

  6. 6

    Distinct only on one column

  7. 7

    DISTINCT to only one column

  8. 8

    Select distinct for one column

  9. 9

    Select multiple columns with only one distinct column in sql

  10. 10

    MySQL LEFT JOIN only one row, ordered by column without subquery

  11. 11

    MySQL LEFT JOIN only one row, ordered by column without subquery

  12. 12

    How to left join with or operator and determined only one column that match

  13. 13

    Postgres: Distinct but only for one column

  14. 14

    Postgres: Distinct but only for one column and latest one

  15. 15

    Postgres: Distinct but only for one column and latest one

  16. 16

    Distinct by Category then Join all distinct values per Category in one column

  17. 17

    Select only 1 distinct column - SQL

  18. 18

    SQL return only distinct IDs from LEFT JOIN

  19. 19

    How to left_join() two datasets but only select specific columns from one of the datasets?

  20. 20

    sql - how to select multiple columns with only one distinct column from joining multiple tables

  21. 21

    Select multiple columns with only one distinct column in SQL Server Compact Edition

  22. 22

    Where clause for only one table in a left join

  23. 23

    why this left join returns only one record?

  24. 24

    Show only one result in sql LEFT JOIN

  25. 25

    Hide column from a left join select

  26. 26

    Insert distinct values only for one column

  27. 27

    mysql using DISTINCT for only one column

  28. 28

    Insert distinct values only for one column

  29. 29

    Select all from Table A, one column from Table B - LEFT JOIN

HotTag

Archive