Welcome Guest, Not a member yet? Register   Sign In
How can I perform a MYSQL search query that returns two different sets of results at the same time?
#1

[eluser]Dandy_andy[/eluser]
I’m performing a MYSQL query that selects certain information from a table and returns 12 results (using LIMIT). However, I have now run into a situation where I need to split those 12 results into two different queries of 6 results each. So essentially what I’d like to do is get the results of query 1 (6 of them) and also the results of query 2 (6 of them) and combine them so that the return value is 12 in total (6 + 6). I’ve just been reading about transactions – is this the right way to do this or is there another method? I have illustrated what I’m trying to do below (very simplified – obviously the statements below don’t work)

Code:
$this->db->select('*');
$this->db->from('members');
$this->db->where('sex', 'female');
$this->db->limit(6);

$this->db->select('*');
$this->db->from('members');
$this->db->where('sex', 'male');
$this->db->limit(6);

$query = $this->db->get();

The intention is to ensure the results always return 6 male members and 6 female members regardless of the search criteria (there are far more options but not listed above).

Any help is appreciated. Thanks.


Messages In This Thread
How can I perform a MYSQL search query that returns two different sets of results at the same time? - by El Forum - 09-18-2012, 01:37 AM



Theme © iAndrew 2016 - Forum software by © MyBB