简体   繁体   中英

Selecting distinct column values in NOTORM

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 ie 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')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM