marcick Well-Known Member Licensed User Longtime User Oct 18, 2018 #1 I know yhis is not the correct place, but I googled much without success ... I need to find the minimum value between the maximum value in a column and a constant In my mnd the sintax would be this but doesn't work SELECT LEAST(SELECT MAX(columnname) FROM records, 100); Any help ?
I know yhis is not the correct place, but I googled much without success ... I need to find the minimum value between the maximum value in a column and a constant In my mnd the sintax would be this but doesn't work SELECT LEAST(SELECT MAX(columnname) FROM records, 100); Any help ?
BillMeyer Well-Known Member Licensed User Longtime User Oct 18, 2018 #2 Correct Syntax would be: SELECT MIN(Price) AS SmallestPrice FROM Products; SELECT MAX(Price) AS LargestPrice FROM Products; SELECT column_name(s) FROM table_name WHERE column_name BETWEEN value1 AND value2; So let's put it all together: Select Min(columnname) From table_Name where columnname BETWEEN 1 AND 100 - (1 and 100 you now again can substitute with any variable you like) More Information: https://www.w3schools.com/sql/default.asp Hope this helps Upvote 0
Correct Syntax would be: SELECT MIN(Price) AS SmallestPrice FROM Products; SELECT MAX(Price) AS LargestPrice FROM Products; SELECT column_name(s) FROM table_name WHERE column_name BETWEEN value1 AND value2; So let's put it all together: Select Min(columnname) From table_Name where columnname BETWEEN 1 AND 100 - (1 and 100 you now again can substitute with any variable you like) More Information: https://www.w3schools.com/sql/default.asp Hope this helps
marcick Well-Known Member Licensed User Longtime User Oct 18, 2018 #3 Hi, probably I didn't explain well. I need the minimum value between two object object 1: is the maximum value of the primary key of my table. I obtain this with SELECT MAX('Index') FROM records object 2: is a number that i pass as parameter in JRDC2 command. So it is a '?' in a command inside config.propertis file of JRDC2 Upvote 0
Hi, probably I didn't explain well. I need the minimum value between two object object 1: is the maximum value of the primary key of my table. I obtain this with SELECT MAX('Index') FROM records object 2: is a number that i pass as parameter in JRDC2 command. So it is a '?' in a command inside config.propertis file of JRDC2
LucaMs Expert Licensed User Longtime User Oct 18, 2018 #4 SELECT MIN(MAX('Index'), 100) FROM records Upvote 0
marcick Well-Known Member Licensed User Longtime User Oct 18, 2018 #5 LucaMs said: SELECT MIN(MAX('Index'), 100) FROM records Click to expand... eh si, purtroppo da errore di sintassi ..... Looks good, but give a sintax error .... Last edited: Oct 18, 2018 Upvote 0
LucaMs said: SELECT MIN(MAX('Index'), 100) FROM records Click to expand... eh si, purtroppo da errore di sintassi ..... Looks good, but give a sintax error ....
OliverA Expert Licensed User Longtime User Oct 18, 2018 #6 Try B4X: SELECT IF(MAX(Index) < 100, MAX(Index), 100) FROM records With parameters B4X: SELECT IF(MAX(Index) < ?, MAX(Index), ?) FROM records You would have to supply the same parameter twice (once for each ?) Upvote 0
Try B4X: SELECT IF(MAX(Index) < 100, MAX(Index), 100) FROM records With parameters B4X: SELECT IF(MAX(Index) < ?, MAX(Index), ?) FROM records You would have to supply the same parameter twice (once for each ?)
marcick Well-Known Member Licensed User Longtime User Oct 18, 2018 #7 OliverA said: Try B4X: SELECT IF(MAX(Index) < 100, MAX(Index), 100) FROM records Click to expand... I think we are close to the solution, but still this does not work Upvote 0
OliverA said: Try B4X: SELECT IF(MAX(Index) < 100, MAX(Index), 100) FROM records Click to expand... I think we are close to the solution, but still this does not work
OliverA Expert Licensed User Longtime User Oct 18, 2018 #8 marcick said: but still this does not work Click to expand... Such as? Upvote 0
marcick Well-Known Member Licensed User Longtime User Oct 18, 2018 #9 OliverA said: Such as? Click to expand... Upvote 0
OliverA Expert Licensed User Longtime User Oct 18, 2018 #10 Quit quoting Index. That gives MAX a String, not the column name. BTW, did you notice any quotes in my syntax? Upvote 0
Quit quoting Index. That gives MAX a String, not the column name. BTW, did you notice any quotes in my syntax?
LucaMs Expert Licensed User Longtime User Oct 18, 2018 #11 It works. The only problem is that max is calculated twice. Upvote 0
marcick Well-Known Member Licensed User Longtime User Oct 18, 2018 #12 I have to quote Index (I think it is a reserved word, bad idea to use it as column name) If I write SELECT MAX(Index) FROM record give an error I'm discovering the problem is the quoting character: SELECT IF(MAX(`Index`) < 50, MAX(`Index`), 50) FROM records works SELECT IF(MAX('Index') < 50, MAX('Index'), 50) FROM records does not work Upvote 0
I have to quote Index (I think it is a reserved word, bad idea to use it as column name) If I write SELECT MAX(Index) FROM record give an error I'm discovering the problem is the quoting character: SELECT IF(MAX(`Index`) < 50, MAX(`Index`), 50) FROM records works SELECT IF(MAX('Index') < 50, MAX('Index'), 50) FROM records does not work
marcick Well-Known Member Licensed User Longtime User Oct 18, 2018 #13 Finally: This works fine (with the correct quoting character) SELECT LEAST(MAX(`Index`), 10) FROM records Thanks everybody for the support ! Upvote 0
Finally: This works fine (with the correct quoting character) SELECT LEAST(MAX(`Index`), 10) FROM records Thanks everybody for the support !
OliverA Expert Licensed User Longtime User Oct 18, 2018 #14 marcick said: I have to quote Index (I think it is a reserved word, bad idea to use it as column name) Click to expand... I used the unquoted with MySQL and it worked fine. marcick said: I'm discovering the problem is the quoting character: Click to expand... Yup. LucaMs said: The only problem is that max is calculated twice. Click to expand... I would say that depends on the "smartness" of the SQL engine. marcick said: SELECT LEAST(SELECT MAX(columnname) FROM records, 100); Click to expand... This is hilarious: B4X: SELECT LEAST(MAX(Index), 100) FROM records works. Upvote 0
marcick said: I have to quote Index (I think it is a reserved word, bad idea to use it as column name) Click to expand... I used the unquoted with MySQL and it worked fine. marcick said: I'm discovering the problem is the quoting character: Click to expand... Yup. LucaMs said: The only problem is that max is calculated twice. Click to expand... I would say that depends on the "smartness" of the SQL engine. marcick said: SELECT LEAST(SELECT MAX(columnname) FROM records, 100); Click to expand... This is hilarious: B4X: SELECT LEAST(MAX(Index), 100) FROM records works.
marcick Well-Known Member Licensed User Longtime User Oct 18, 2018 #17 The problem with the quoting character is in PhpMyAdmin. I'll see what happens in JRDC2 Upvote 0
LucaMs Expert Licensed User Longtime User Oct 18, 2018 #18 MS Sql Server accepts square brackets too ! Damn syntax Upvote 0
LucaMs Expert Licensed User Longtime User Oct 18, 2018 #19 LucaMs said: MS Sql Server accepts square brackets too ! Damn syntax Click to expand... .... and this: LucaMs said: SELECT MIN(MAX('Index'), 100) FROM records Click to expand... works on SQLite. Upvote 0
LucaMs said: MS Sql Server accepts square brackets too ! Damn syntax Click to expand... .... and this: LucaMs said: SELECT MIN(MAX('Index'), 100) FROM records Click to expand... works on SQLite.
marcick Well-Known Member Licensed User Longtime User Oct 18, 2018 #20 LucaMs said: MS Sql Server accepts square brackets too ! Damn syntax Click to expand... What is amazing with SQL is that any condition you have in mind can be done. Looks like there are no limits. Just have to find the sintax ... Upvote 0
LucaMs said: MS Sql Server accepts square brackets too ! Damn syntax Click to expand... What is amazing with SQL is that any condition you have in mind can be done. Looks like there are no limits. Just have to find the sintax ...