Welcome Guest, Not a member yet? Register   Sign In
Using subqueries
#1

[eluser]ThatDaveCarter[/eluser]
Hi,

I'm currently executing a query using $this->db->query($sql,$data), which has worked fine for me so far, however the query now needs some adjustments, and needs to contain a subquery. I'm having trouble figuring out a way to do this, and was wondering what the best way to do this in CI would be.

My current MySQL query reads similar to this:
Code:
SELECT * FROM `table` where `forename` like '%%' AND `surname` like '%%'

I need to update it to this:

Code:
SELECT * FROM `table` where (`forename` like '%%' AND `surname` like '%%') OR userid in ((select userid from `genres` where `genre` like '%genre1%' or `genre` like '%genre2%'))

The Genres part of this query will be dynamic, depending on input from a HTML form (an array of items is posted)

I've tried numerous iterations that I can think of, to no avail. My head is fried right now.. Any tips/guidance please?

Regards,

Dave


Messages In This Thread
Using subqueries - by El Forum - 06-16-2012, 10:40 AM
Using subqueries - by El Forum - 06-16-2012, 03:14 PM
Using subqueries - by El Forum - 06-20-2012, 11:00 AM
Using subqueries - by El Forum - 06-21-2012, 01:08 AM
Using subqueries - by El Forum - 06-21-2012, 01:57 AM
Using subqueries - by El Forum - 06-21-2012, 02:02 AM
Using subqueries - by El Forum - 06-21-2012, 02:53 AM



Theme © iAndrew 2016 - Forum software by © MyBB