Insert multiple columns in one new mysql table

I try to insert columns for two different tables into one new table.
I try following query:

$sql = “INSERT INTO groepering (datum, uur, injectieDag, injectieNacht, power, energy)
SELECT VerschilBerekeningInjectie.datum as datum,
VerschilBerekeningInjectie.uur as uur ,
VerschilBerekeningInjectie.injectieDag as injectieDag,
VerschilBerekeningInjectie.injectieNacht as injectieNacht,
dagOpbrengstKostal.power as power, as energy FROM VerschilBerekeningInjectie
LEFT JOIN dagOpbrengstKostal ON VerschilBerekeningInjectie.datum = dagOpbrengstKostal.datum and VerschilBerekeningInjectie.uur = dagOpbrengstKostal.uur WHERE VerschilBerekeningInjectie.datum = ‘2020-12-18’”;

the select query works, but the insert action doesn’t.
no data are inserted, no error displayed.

simplified query –

  INTO groepering 
     ( datum
     , uur
     , injectieDag
     , injectieNacht
     , power
     , energy )
SELECT v.datum
     , v.uur
     , v.injectieDag
     , v.injectieNacht
     , d.power 
  FROM VerschilBerekeningInjectie  AS v
  JOIN dagOpbrengstKostal  AS d 
    ON d.datum = v.datum 
   and d.uur   = v.uur 
 WHERE v.datum = '2020-12-18'

looks like you’re running php… with MySQL?

did you try the INSERT statement directly in the database, i.e. not via php?

could you do a SHOW CREATE TABLE for groepering please?

What is the purpose of you doing this? Your are using a specific day date to put this data in a new table. Whatever you are doing, this is a flawed approach. All you need to do is create a View to work with this dateset in an easier manner. You will end up with a cluster muck of tables and duplicate data if you do this for every day you want to do something with the data.

@r937, @benanamen,
Thank you for your reactions.
Problem is now solved: the query resulted i in a number of cases in a NULL, but in Structure tab of the table the “NULL” checkbox was not checked, so the insert action could not proceed.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.