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

  • PraveenKumar Purushothaman
    PraveenKumar Purushothaman
    Yeah, you can use sub queries in your where clause, and for more values, use in... 😀
  • Manish Goyal
    Manish Goyal
    Bingo
    anyway I had use IN with subquery 😀

You are reading an archived discussion.

Related Posts

I am totally confused about future because of after b.tech i joined an IT Company in Jaipur in SEO Executive but salary matters for me and before this company i...
Hey CEians, I need some help here as I'm still a student exploring the mighty worlds of engineering, so please feel free to suggest/comment/criticize. I have had a plan in...
Shirt capable of converting body heat into electricity | News | The Engineer
Hovering robot uses cameras to navigate through buildings | News | The Engineer
CEans, We think this is quite tough puzzle; but certainly not for our awesome CEans. The question below carries 15 CE Coins. The puzzle is a sequence of numbers and...