I inherited a particular code from a previous developer. I intend to build the application all over again, but I have to add some functionalities before I proceed.
Firstly, It's a 62 column table that has to do with accounting, and I also have to fetch values from different tables with a single call to get the values that I need before insertion.
Lets say I need to make an insertion into table dailysales and i need to get values from table a,b,c and d at the same time.
I already have an sql statement for fetching this values, and it works fine except that a particular column keeps returning as NULL.
Here's my code:
SELECT `gds_pnr_ref`, `transaction_date`,
(SELECT `lastname` FROM `a` WHERE `id` = `staff` LIMIT 1) as `lastname`,
(SELECT `firstname` FROM `a` WHERE `id` = `staff` LIMIT 1) as `firstname`,
(SELECT `department_name` FROM `b` WHERE `id` = `staff_department` LIMIT 1) as `department`,
(SELECT `name` FROM `b` WHERE `memo_serial` = '$some_value' LIMIT 1) as `pax_name`,
(SELECT `customer_name` FROM `c` WHERE `id` = `customer_name` LIMIT 1) as `customer`,
travel_product,
(SELECT `vendor_name` FROM `c` WHERE `id` = `vendor` LIMIT 1) as `vendor`
FROM `d` WHERE `id` = '$some_value' LIMIT 1
The column (SELECT customer_name FROM c WHERE id = customer_name LIMIT 1) as customer always returns as NULL but when i run it independently it gives me the appropriate value.
I'm very much opened to a better solution for going about this.
id=customer_name? I expect a number onidand a string oncustomer_name. So they can't be equal.staff,staff_department,customer_nameandvendorare all columns of tabled