Craig
Craig

Reputation: 139

How to Concat results without duplicates when using "Like"

I'm attempting to adapt the following query so that in Concats the results without any duplicates.

SELECT `increment_id`
FROM `sales_order`
WHERE `remote_ip`
LIKE '123.123.123.123'

Based on this post, I have adapted the query to the following:

SELECT `remote_ip`, GROUP_CONCAT(DISTINCT `increment_id` SEPARATOR ', ')
FROM `sales_order`
GROUP BY `remote_ip`

However, I'm struggling to find a place to add LIKE '123.123.123.123' without causing an error.

Upvotes: 0

Views: 59

Answers (1)

Madhur Bhaiya
Madhur Bhaiya

Reputation: 28834

You simply need to add the WHERE condition after your FROM clause, to filter the data accordingly:

SELECT `remote_ip`, GROUP_CONCAT(DISTINCT `increment_id` SEPARATOR ', ')
FROM `sales_order`
WHERE `remote_ip` LIKE '123.123.123.123'
GROUP BY `remote_ip`

Upvotes: 1

Related Questions