Advertisement
Guest User

SQL union for one identical column

a guest
Sep 12th, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 0.54 KB | None | 0 0
  1. CREATE TABLE IF NOT EXISTS `test` (
  2.   `idtest` INT NOT NULL AUTO_INCREMENT,
  3.   `label` VARCHAR(45) NULL,
  4.   `translation` VARCHAR(45) NULL,
  5.   `language` VARCHAR(45) NULL,
  6.   PRIMARY KEY (`idtest`))
  7. ENGINE = InnoDB
  8.  
  9. insert into test values (1, 'lbl1' , 'NAME', 'English');
  10. insert into test values (2, 'lbl1' , 'N4M3' , 'EnglishCustom');
  11.  
  12. SELECT COALESCE(t2.translation,t1.translation)
  13. FROM test t1
  14.   LEFT JOIN test t2
  15.          ON t1.label = t2.label
  16.         AND t2.language = CONCAT (t1.language,'Custom')
  17. WHERE t1.language = 'English';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement