M
M
Miroslav Prikhodko2017-08-28 07:56:23
PostgreSQL
Miroslav Prikhodko, 2017-08-28 07:56:23

How to find the maximum value of a column in a table?

The bottom line is that there is a posgresql database, it is necessary in the users database to determine the maximum value in the id field in MySQL, I ran the query SELECT MAX( id) FROM users; and everything worked now i get an empty response.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
Orbite, 2017-08-28
@Orbite

SELECT MAX(id) FROM users WHERE id is not null

B
Bogdan, 2017-08-28
@bogdan_uman

I use system tables, it's more reliable and better in terms of performance

_lenght_number = ( SELECT aa.character_maximum_length FROM INFORMATION_SCHEMA.COLUMNS aa
                                 WHERE aa.table_name = TG_TABLE_NAME AND column_name = 'number' );

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question