samtwilliams Posted October 28, 2012 Share Posted October 28, 2012 (edited) I need to selected the subscriber_Id from another tabled based on an email address, can't seem to work out why this nested select won't work. Can someone help Thanks Sam INSERT INTO `pommo_subscriber_data` ( `data_id` , `field_id` , `subscriber_id` , `value` ) VALUES ( NULL , '1', (SELECT `pommo_subscribers`.`subscriber_id` FROM `pommo_subscribers` WHERE `pommo_subscribers`.`email` = 'samtwilliams23'ORDER BY `pommo_subscribers`.`subscriber_id` DESC), 'SamTEST'); Edited October 28, 2012 by samtwilliams Quote Link to comment https://forums.phpfreaks.com/topic/270004-insert-with-a-nested-select/ Share on other sites More sharing options...
Psycho Posted October 28, 2012 Share Posted October 28, 2012 (edited) That is not how you do an INSERT with a select. Take a look at the manual for that: http://dev.mysql.com...ert-select.html I have no idea why you are inserting a NULL value for the first record - why not just leave that field out of the insert? Also, what is the purpose of putting an ORDER BY on the select that us being used to insert all the records? This might be closer to what you want INSERT INTO `pommo_subscriber_data` (`data_id`, `field_id`, `subscriber_id`, `value`) SELECT NULL, 1, `pommo_subscribers`.`subscriber_id`, 'SamTEST' FROM `pommo_subscribers` WHERE `pommo_subscribers`.`email` = 'samtwilliams23' Edited October 28, 2012 by Psycho Quote Link to comment https://forums.phpfreaks.com/topic/270004-insert-with-a-nested-select/#findComment-1388295 Share on other sites More sharing options...
fenway Posted November 1, 2012 Share Posted November 1, 2012 Probably because it's an auto-increment value -- but still a bad, bad idea. Quote Link to comment https://forums.phpfreaks.com/topic/270004-insert-with-a-nested-select/#findComment-1389176 Share on other sites More sharing options...
Muddy_Funster Posted November 1, 2012 Share Posted November 1, 2012 I'm with Psycho - why in the name of everything that is sinful (it's a way bigger list than all that is holy) would you ever activly insert a null value into a table? if null is allowed, it should be a default value and nothing should be inserted into that field in the event that nothing is indeed being inserted into that field. during an update, fair enough, but for an insert? Quote Link to comment https://forums.phpfreaks.com/topic/270004-insert-with-a-nested-select/#findComment-1389336 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.