Solve this real sql problem

Manish Goyal

Manish Goyal

@manish-r2Hoep Oct 25, 2024
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?

Replies

Welcome, guest

Join CrazyEngineers to reply, ask questions, and participate in conversations.

CrazyEngineers powered by Jatra Community Platform

  • ISHAN TOPRE

    ISHAN TOPRE

    @ishan-nohePN Dec 22, 2011

    Yeah, you can use sub queries in your where clause, and for more values, use in... 😀
  • Manish Goyal

    Manish Goyal

    @manish-r2Hoep Dec 22, 2011

    Bingo
    anyway I had use IN with subquery 😀