CrazyEngineers
  • Manish
    Manish

    MemberNov 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?
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • ISHAN TOPRE

    MemberDec 22, 2011

    Yeah, you can use sub queries in your where clause, and for more values, use in... 😀
    Are you sure? This action cannot be undone.
    Cancel
  • Manish Goyal

    MemberDec 22, 2011

    Bingo
    anyway I had use IN with subquery 😀
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register