-1

I want to get values with DISTINCT but it has to include a spesific value only once ever it hasn't got. For example DISTINCT gets "John, Gabriel, Alisia, George" so the "Johann" must added but, if DISTINCT already returns with "Johann" like "John, Gabriel, Alisia, George, Johann" so no need to add again. I cant figure my SQL. using MySQL and PHP.

Anand Solanki
  • 3,287
  • 4
  • 12
  • 26
caglaror
  • 398
  • 1
  • 12
  • 26
  • 2
    Can you post sample data and desired results. Having a difficult time understanding your question. – sgeddes May 13 '14 at 12:39
  • Your question is not clear to me, please post sample data and the actual query, that you run. – user4035 May 13 '14 at 12:40
  • I need a result set that always includes a value whenever it never recorded to table. Bu if it also between the result no need to add again. – caglaror May 13 '14 at 12:53
  • That's what the DISTINCT keyword does. Please edit your question and put the current query you're u sing. – ajacian81 May 13 '14 at 13:16
  • I cant figure out any query at the moment. DISTINCT only filter what has table got. I want to return a result set which includes a spesific value in every condition whether DISTINCT gets or not. But if this spesific value returned between the result set with DISTINCT, no need to add it again. – caglaror May 13 '14 at 13:34
  • Also my data set isn't suitable to run this query yet. I am planning to modify it if there construct the sql :/ – caglaror May 13 '14 at 13:35

1 Answers1

-1

If you're doing a GROUP_CONCAT then you can do a DISTINCT one, such as:

SELECT GROUP_CONCAT(DISTINCT name) FROM some_table;

See also: MySQL DISTINCT on a GROUP_CONCAT()

Community
  • 1
  • 1
ajacian81
  • 6,673
  • 8
  • 46
  • 63