Find max for varchar

Hi, I am working on a java project where I need to get the latest id id Max(c_id) client Max(c_id) . But there is text (varchar) in my c_id database, so how can I get max?

  Connection conn; Statement st; Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); conn=DriverManager.getConnection("jdbc:odbc:rrr"); st=conn.createStatement(); String query[] ={"SELECT Max(cid) FROM client"}; for(String q : query){ ResultSet rs = st.executeQuery(q); while (rs.next()) { String name = rs.getString("cid"); Text1.setText(name); 
+4
source share
7 answers

Please note the following:

select * from the sales order using cid desc limit 1,1;

0
source

select max(convert(integer, c_id)) or select max(cast(c_id as integer)) should work

+3
source

Using

  select max(c_id::integer) from tbluser ; 

If you are using postgresql database

+3
source

Check this,

 SELECT max(convert(c_id, signed)) FROM client 

try this in mysql,

 SELECT max(cast(c_id AS signed)) FROM client 

can you check with cint function to use ms access

+1
source

Use this query:

select max (convert (cid, DECIMAL)) from the client;

0
source

Please use the following query.

select * from customer order c_id desc limit 1,1;

0
source

MySQL

 SELECT Max(cast(cid as signed)) FROM client 

Oracle

 SELECT Max(to_number(cid)) FROM client 

MSSQL

 SELECT Max(CONVERT(int, cid)) FROM client 
0
source

Source: https://habr.com/ru/post/1391778/


All Articles