Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

sql query syntax for limit, minimum and maximum values

 
Assh Khan
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Dear,
I am trying to write a java program that gets the data from the databases. I am having problem with the SQL query that reads a number of records, minimum and maximum values stored in three variables . I have tried simple queries before. I'll be greatly thankful to you if someone helps me in finding out the proper syntax.

Thank you
 
Assh Khan
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am now trying this syntax, able to read values but again showing me an error, Please help me out as i am unable to figure out the error


error is as follows :

Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'where MIN(Transaction_Value) = 5 & MAX(Transaction_Value) = 100' at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:377)
at com.mysql.jdbc.Util.getInstance(Util.java:360)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:978)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3887)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3823)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2435)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2582)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2530)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1907)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2030)
at transactions.main.main(main.java:52)
Java Result: 1
Thank you
 
Tushar Goel
Ranch Hand
Posts: 927
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not database guy but quick google told me that some of database doesn't support LIMIT in this way. You can try this as well:

SELECT column_name(s)
FROM table_name
LIMIT number;
 
Assh Khan
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tushar Goel wrote:I am not database guy but quick google told me that some of database doesn't support LIMIT in this way. You can try this as well:

SELECT column_name(s)
FROM table_name
LIMIT number;


my query without min and max value works well with limit but i don't know how to add minimum and maximum values in it, really struggling
 
Dave Tolls
Ranch Hand
Posts: 2095
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are you trying to do?
What is the MIN and MAX for?

If you're trying to get all the rows where TransactionValue is between two values then use < and >.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic