问题描述:

My MySQL table look like this:

 'id' 'name' 'type'

1 name1 A

2 name2 B

3 name3 A

4 name4 C

5 name5 C

How can I get all distinct types i.e A, B, C in NOTORM PHP.

网友答案:

The API docs don't cover it off in an intuitive manner, but you need to simply use the group by function to get distinct values:

$table->group($columns[, $having])

Set GROUP BY and HAVING

This is the same (not at a db level, but the same at an output level) of running a distinct.

There isn't an anchor to the exact part, but it is in here: http://www.notorm.com/#api

网友答案:

Use the sql query

SELECT DISTINCT type FROM yourtable

using the notORM API that would be:

('SELECT DISTINCT type FROM ') $table

Another possibility is using the work arround:

$table->select('DISTINCT type')
相关阅读:
Top