I am trying to insert a record into a table where the table fields are related to ther tables.
It is not necessary to have entries in each table for the record to insert so I'm trying to insert either values or NULL into the main insert's table.
INSERT INTO `table-a` (`field1`,`field2`,`field3`,`field4`)
SELECT 'one',`b`.`tbl_id`,`c`.`table_id`,`d`.`table_id`
FROM `table-b` `b`
LEFT JOIN `table-c` `c` ON `c`.`title` = 'some title'
LEFT JOIN `table-d` `d` ON `d`.`title` = 'another tile'
WHERE `b`.`title` = 'yet another title'
I Had IF (b.table_id IS NULL, NULL, b.tab;e_id) before but that didnt resolve my problem, if not all conditions are met no rows are returned and therefore there are no NULL values.
How can I do this so that if a table doesnt match I can still return a NULL for that specific field,
all of table-a's fields can be NULL.