Manish
Member • Nov 4, 2011
Solve this real sql problem
Today i was working on some project and i was facing this issue of getting data from multiple tables
The problem was, I have a static function where a certain query that will be used to fetch data was already defined (Note you can't alter this function)
It takes only one argument i.e. where clause conditions
The query was written like this
SELECT vtiger_crmentity.crmid, vtiger_crmentity.smownerid, vtiger_troubletickets.title, vtiger_troubletickets.status, vtiger_troubletickets.priority, vtiger_troubletickets.parent_id, vtiger_contactdetails.contactid, vtiger_contactdetails.firstname, vtiger_contactdetails.lastname, vtiger_account.accountid, vtiger_account.accountname, vtiger_ticketcf.*, vtiger_troubletickets.ticket_no FROM vtiger_troubletickets INNER JOIN vtiger_ticketcf ON vtiger_ticketcf.ticketid = vtiger_troubletickets.ticketid INNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid = vtiger_troubletickets.ticketid LEFT JOIN vtiger_groups ON vtiger_groups.groupid = vtiger_crmentity.smownerid LEFT JOIN vtiger_contactdetails ON vtiger_troubletickets.parent_id = vtiger_contactdetails.contactid LEFT JOIN vtiger_account ON vtiger_account.accountid = vtiger_troubletickets.parent_id LEFT JOIN vtiger_users ON vtiger_crmentity.smownerid = vtiger_users.id LEFT JOIN vtiger_products ON vtiger_products.productid = vtiger_troubletickets.product_id where vtiger_crmentity.cid = 0 and " .
Here where clause conditions will be append after and
Now i have to add condition which depends on other table (Table may return single row or multiple row)
How can i do this
You may assume table say 'vtiger_accounts'
Can you solve this?
The problem was, I have a static function where a certain query that will be used to fetch data was already defined (Note you can't alter this function)
It takes only one argument i.e. where clause conditions
The query was written like this
SELECT vtiger_crmentity.crmid, vtiger_crmentity.smownerid, vtiger_troubletickets.title, vtiger_troubletickets.status, vtiger_troubletickets.priority, vtiger_troubletickets.parent_id, vtiger_contactdetails.contactid, vtiger_contactdetails.firstname, vtiger_contactdetails.lastname, vtiger_account.accountid, vtiger_account.accountname, vtiger_ticketcf.*, vtiger_troubletickets.ticket_no FROM vtiger_troubletickets INNER JOIN vtiger_ticketcf ON vtiger_ticketcf.ticketid = vtiger_troubletickets.ticketid INNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid = vtiger_troubletickets.ticketid LEFT JOIN vtiger_groups ON vtiger_groups.groupid = vtiger_crmentity.smownerid LEFT JOIN vtiger_contactdetails ON vtiger_troubletickets.parent_id = vtiger_contactdetails.contactid LEFT JOIN vtiger_account ON vtiger_account.accountid = vtiger_troubletickets.parent_id LEFT JOIN vtiger_users ON vtiger_crmentity.smownerid = vtiger_users.id LEFT JOIN vtiger_products ON vtiger_products.productid = vtiger_troubletickets.product_id where vtiger_crmentity.cid = 0 and " .
Here where clause conditions will be append after and
Now i have to add condition which depends on other table (Table may return single row or multiple row)
How can i do this
You may assume table say 'vtiger_accounts'
Can you solve this?