I have this SQL statement which I could not get to work, and I’m not sure what I’m doing wrong.
This is the SQL :
INSERT INTO data
(id_user,id_inf)
VALUES
(
(SELECT userid FROM t4_adsmanager_ads WHERE userid NOT IN (select id_user from data) ),
(SELECT id FROM t4_adsmanager_ads WHERE id NOT IN (select id_inf from data))
)
as what I wanted to do is in t4_adsmanager_ads I have ads created by users
Let’s say user in t4_adsmanager_ads with id = 47 have ads with id= 1,2,3
in data table I have
id id_inf id_user
and i want it to be like that
id id_inf id_user
50 1 47
51 2 47
52 3 47
edit :
my errors is no error just did not work
thx
Your current syntax requires that the subselects return exactly one record, which is not the case in your example.
I suggest you create a
UNIQUEindex in thedatatable over the composite columns(id_user, id_inf):And then you merely need use
INSERT ... SELECTwith theIGNOREmodifier: