Welcome Guest, Not a member yet? Register   Sign In
How do produce SELECT DISTINCT with active records?
#1

[eluser]chefnelone[/eluser]
Hello

I'd like to know how do produce SELECT DISTINCT with active records?

thanks
#2

[eluser]mddd[/eluser]
Check the manual: unsurprisingly, $this->db->distinct() will set your query to use 'distinct'.
#3

[eluser]chefnelone[/eluser]
Do I need to do something else to get distinct to work?

I've got this code... but distinct is just ignored:

Code:
$this->db->distinct('url');
$pages_seo = $this->db->get('pages_seo');
$data = $pages_seo->result();
What I need is to get all records that have different value in the 'url' table field. But I get all records instead.
#4

[eluser]mddd[/eluser]
You cannot use 'distinct' that way. Distinct is just a on/off value. If Distinct is on, Mysql returns all the rows that are not entirely the same. And because there probably are other fields that ARE different, you are still getting all those rows.

You have two options:
1. Use Select to only select the right fields. If the entire row is the same, Distinct WILL work (but you don't have to put 'url', that doesn't do anything!)
2. Use Group_by instead of Distinct to specify the field you want to use for checking uniqueness.
#5

[eluser]chefnelone[/eluser]
[quote author="mddd" date="1275919453"]You cannot use 'distinct' that way. Distinct is just a on/off value. If Distinct is on, Mysql returns all the rows that are not entirely the same. And because there probably are other fields that ARE different, you are still getting all those rows.

You have two options:
1. Use Select to only select the right fields. If the entire row is the same, Distinct WILL work (but you don't have to put 'url', that doesn't do anything!)
2. Use Group_by instead of Distinct to specify the field you want to use for checking uniqueness.[/quote]
Thanks mddd




Theme © iAndrew 2016 - Forum software by © MyBB