Basic Mysql Query : label 2

Swap columns in MySQL
Name1   |   Name2
Saurabh |   Kumar
Praveen |   Kumar
Query:
update temp set name1=(@temp:=name1) , name1 = name2, name2=@temp
Or
update temp t1, temp t2 set t1.name1 = t1.name2, t2.name2 = t2.name1

Concat Mysql
select concat(firstname," ", middlename," ", lastname); // will not work if middlename or anyother field has null values
select concat_ws(" ", firstname,middlename,lastname); // will work if middlename or anyother field has null values

Mysql duplicate issue:
We have 2 columns in a table. say "brand_id" and "name". Now, name is coming duplicate. We have use distinct or group by on name, it works fine with one column "name".
But if we require brand_id with name (both fields), it won't work.
Solution
SELECT MIN(brand_id), name FROM brands GROUP BY name

Comments