2013 Mar 18 5:04 PM - edited 2013 Mar 18 6:04 PM
Preface: That's one of the SQL pitfalls I've stumbeld over too often...
Well, sometimes I've to turn expressions from an ordinary programming language into a SQL query, and sometimes these expressions contain the classical scalar max() function, say like "where max(expr1, expr2) > 0".
The following (absolutely senseless) query would be a sample:
select * from systab where max(table_page_count, ext_page_count) > 10;
Of course, using max() that way in a SQL query is doomed to fail, as MAX() is an aggregate function and works on rows of data, not on two (or more) separate expressions, so this raises
Question: Is there a way to use max() as intended here?
Request clarification before answering.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for the votes: You like to learn from my mistakes, don't you:)
Feel free to tell about your favourite pitfallslearning experiences, too...
It should be noted that GREATER() and LESSER() are vendor extensions (as documented), so for portable SQL, one would probably need to
Aside: I had thought of suggesting an IF expression here - but that's another one of these very helpful vendor extension itself:)
User | Count |
---|---|
25 | |
22 | |
8 | |
8 | |
7 | |
5 | |
4 | |
4 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.