code_junkie

Select from same table as an Insert or Update

Nov 11th, 2011
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. INSERT INTO `aTable` (`A`,`B`) VALUES((SELECT MAX(`A`) FROM `aTable`)*2),'name');
  2.  
  3. INSERT INTO `aTable` (`A`, `B` )
  4. VALUES
  5. (
  6. (
  7. SELECT MAX(`A`)
  8. FROM `aTable`
  9. ) *2
  10. , 'name'
  11. )
  12.  
  13. insert into aTable select max(a)^2, 'name' from aTable;
  14.  
  15. insert into aTable select max(a)^2, 'name' from aTable group by B;
  16.  
  17. insert into aTable select max(a)^2, 'name' from aTable, bTable;
  18.  
  19. INSERT INTO `aTable` (`A`,`B`)
  20. SELECT MAX(`A`)^2,'name' FROM `aTable`
Add Comment
Please, Sign In to add comment