MySQL - Combining INSERT, VALUES, and SELECT? MySQL - Combining INSERT, VALUES, and SELECT? android android

MySQL - Combining INSERT, VALUES, and SELECT?


Makes sense and is called INSERT SELECT. This is an example query for the uniqueDeviceId 123, Score 5 and Difficulty 'easy':

INSERT INTO scores (score, difficulty, playerid)  SELECT 5, 'easy', id  FROM player WHERE uniqueDeviceId = 123;


According to this page you're close. But put all the values into your select. Something like:

insert into scores (score, difficulty, playerid )    select TheScoreThatImProviding, TheDifficultyThatImProviding, player.id       from player where uniqueDeviceId = TheUniqueIdThatImProviding


What about this approach:

INSERT INTO `tableA` SET            columnA =  (SELECT `columnY` FROM `tableY` WHERE `id` = 2),            columnB =  (SELECT `columnZ` FROM `tableB` WHERE `id` = 3);

I didn't benchmarked it yet. But using multiple SELECT statements will burden the Database server. The plus side of this approach is the readability.