ansi-sql

Comparisons with NULLs in SQL

僤鯓⒐⒋嵵緔 提交于 2019-11-28 04:06:06
问题 ANSI-92 SQL mandates that comparisons with NULL evaluate to "falsy," eg: SELECT * FROM table WHERE field = NULL SELECT * FROM table WHERE field != NULL Will both return no rows because NULL can't be compared like that. Instead, the predicates IS NULL and IS NOT NULL have to be used instead: SELECT * FROM table WHERE field IS NULL SELECT * FROM table WHERE field IS NOT NULL Research has shown me that Oracle 1 , PostgreSQL, MySQL and SQLite all support the ANSI syntax. Add to that list DB2 and

There are a method to paging using ANSI SQL only?

扶醉桌前 提交于 2019-11-28 03:13:47
问题 I know: Firebird: FIRST and SKIP ; MySQL: LIMIT ; SQL Server: ROW_NUMBER() ; Does someone knows a SQL ANSI way to perform result paging? 回答1: See Limit—with offset section on this page: http://troels.arvin.dk/db/rdbms/ BTW, Firebird also supports ROWS clause since version 2.0 回答2: No official way, no.* Generally you'll want to have an abstracted-out function in your database access layer that will cope with it for you; give it a hint that you're on MySQL or PostgreSQL and it can add a 'LIMIT'

Does the order of tables in a join matter, when LEFT (outer) joins are used?

ⅰ亾dé卋堺 提交于 2019-11-28 00:41:34
问题 I would like to confirm that the SQL query SELECT .... FROM apples, oranges LEFT JOIN kiwis ON kiwis.orange_id = oranges.id, bananas WHERE .... is exactly equivalent to other permutations in the FROM subclause, like SELECT .... FROM oranges LEFT JOIN kiwis ON kiwis.orange_id = oranges.id, bananas, apples WHERE .... or SELECT .... FROM bananas, apples, oranges LEFT JOIN kiwis ON kiwis.orange_id = oranges.id WHERE .... as long as the explicit LEFT JOIN between oranges and kiwis remains intact.

SQL query with distinct and sum

此生再无相见时 提交于 2019-11-27 23:36:00
I have the following medleys table that combines colors , fruits and ratings : [medleys] medley_id | color | fruit | rating ============================================== 1 red apple 25 2 blue pear 5 3 green apple 12 4 red apple 10 5 purple kiwi 5 6 purple kiwi 50 7 blue kiwi 3 8 blue pear 9 I am trying to write an ANSI-compliant SQL query that will combine every unique/distinct color - fruit pair and sum each pair's individual rating values. Thus if you ran the query on the table above it would produce the following result sets: [query] color | fruit | sum =========================== red

Number of days between two dates - ANSI SQL

核能气质少年 提交于 2019-11-27 23:16:27
I need a way to determine the number of days between two dates in SQL. Answer must be in ANSI SQL. Monkey Boson ANSI SQL-92 defines DATE - DATE as returning an INTERVAL type. You are supposed to be able to extract scalars from INTERVALS using the same method as extracting them from DATEs using – appropriately enough – the EXTRACT function (4.5.3). <extract expression> operates on a datetime or interval and returns an exact numeric value representing the value of one component of the datetime or interval. However, this is very poorly implemented in most databases. You're probably stuck using

Standard SQL boolean operator IS vs. equals (=) operator

那年仲夏 提交于 2019-11-27 23:08:42
问题 On the Wikipedia page for SQL there are some truth tables about boolean logic in SQL. [1] The Wikipedia page seems to source the SQL:2003 standard. The truth table for the equals operator (=) is different from the IS operator from the SQL:2003 draft. Also, the Wikipedia article notes that "IS NULL" (<null predicate>) is a special case. In the SQL:2003 it seems that there is an "IS" opeartor which is a regular operator like AND, NOT and OR. However, the <null predicate> is still there. Why is

Why do I need to explicitly specify all columns in a SQL “GROUP BY” clause - why not “GROUP BY *”?

梦想与她 提交于 2019-11-27 22:58:20
This has always bothered me - why does the GROUP BY clause in a SQL statement require that I include all non-aggregate columns? These columns should be included by default - a kind of "GROUP BY *" - since I can't even run the query unless they're all included. Every column has to either be an aggregate or be specified in the "GROUP BY", but it seems like anything not aggregated should be automatically grouped. Maybe it's part of the ANSI-SQL standard, but even so, I don't understand why. Can somebody help me understand the need for this convention? It's hard to know exactly what the designers

AutoIncrement fields on databases without autoincrement field

无人久伴 提交于 2019-11-27 20:17:29
In MS Sql Server is easy create autoincrement fields. In my systems I stopped to use autoincrement fields for primary keys, and now I use Guid's. It was awesome, I've got a lot of advantages with that change. But in another non-primary key fields, I really was needing implement a "soft autoincrement". It's because my system is DB independent, so I create the autoinc value programatically in c#. I would like about solutions for autoincrement fields on databases without autoincrement, what the solution that your use and why? There is some Sql Ansi statement about this? and generating directly

What does SQL Select symbol || mean?

那年仲夏 提交于 2019-11-27 14:37:18
What does || do in SQL? SELECT 'a' || ',' || 'b' AS letter collapsar || represents string concatenation. Unfortunately, string concatenation is not completely portable across all sql dialects: ansi sql: || (infix operator) mysql: concat ( vararg function ). caution : || means 'logical or' ( It's configurable , however; thanks to @hvd for pointing that out) oracle: || (infix operator), concat ( caution : function of arity 2 only ! ) postgres: || (infix operator) sql server: + (infix operator), concat ( vararg function ) sqlite: || (infix operator) hopefully the confusion is complete ... John

ANSI SQL Manual

纵饮孤独 提交于 2019-11-27 10:47:56
Can anyone recommend a good ANSI SQL reference manual? I don't necessary mean a tutorial but a proper reference document to lookup when you need either a basic or more in-depth explanation or example. Currently I am using W3Schools SQL Tutorial and SQL Tutorial which are ok, but I don't find them "deep" enough. Of course, each major RDBMS producer will have some sort of reference manuals targeting their own product, but they tend to be biased and sometime will use proprietary extensions. EDITED: The aim of the question was to focus on the things database engines have in common i.e. the SQL