问题
I use Knex.js to communicate to Postgres database.
I have rows in a table with a column named 'state' which represents a US state.
How can I retrieve all unique values from this column?
回答1:
You are probably looking for knex.distinct + knex.pluck combo.
knex
.distinct()
.from('tablename')
.pluck('state')
.then(states => {
console.log(states)
})
来源:https://stackoverflow.com/questions/47263583/how-can-i-retrieve-unique-values-from-a-column-with-knex-js