Group the rows and then get different values

I have the following columns in my table: alias, first, last. I would like to concatenate the strings and then look for different values: that is.

  • jimmyWho, jim smith
  • BallyHo, Bob, Smith
  • JimmytwoShoes, Jim, Smith
  • Bobtastic, Bob, Johnson
  • JimmytwoShoes, Jim, Smith
  • BallyHo, Dave, Jones

I would like to get the following results (note that the number 5 above is a duplicate):

  • jimmyWho, jim smith
  • BallyHo, Bob, Smith
  • JimmytwoShoes, Jim, Smith
  • Bobtastic, Bob, Johnson
  • BallyHo, Dave, Jones

In other words, I need to concatenate the strings, and then search for the individual values ​​only AFTER I am concatenated ... by doing this b / f, concatenation will not produce the desired results. Is there any way to do this in mysql?

+4
source share
3 answers

I'm not sure if this is fully applicable to your situation, but you should read the group_concat function to see if it fits your needs. The request may look like

select a separate group group_concat (column) from the table, where the whaterver group is in the common table.

+3
source

Check out DISTINCT

 SELECT DISTINCT alias, first, last FROM users; 

I do not understand your reason for concatenation. However, if the above does not work, you can combine the entries with CONCAT()

 SELECT DISTINCT CONCAT(alias, ', ', first, ', ', last) FROM users; 
+5
source

If I understand what you are asking for, you can make a request similar to this:

 SELECT DISTINCT CONCAT(all the columns or whatever) FROM table 

More on Selecting Individual

+1
source

All Articles