ansi-sql

SQL Joins: Future of the SQL ANSI Standard (where vs join)?

有些话、适合烂在心里 提交于 2019-11-27 06:50:36
问题 We are developing ETL jobs and our consultant has been using "old style" SQL when joining tables select a.attr1, b.attr1 from table1 a, table2 b where a.attr2 = b.attr2 instead of using the inner join clause select a.attr1, b.attr1 from table1 as a inner join table2 as b on a.attr2 = b.attr2 My question is that in the long run, is there a risk for using the old "where join"? How long this kind of joins are supported and kept as ANSI standard? Our platform is SQL Server and my primary cause is

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

落花浮王杯 提交于 2019-11-27 04:34:32
问题 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

SQL query with distinct and sum

蓝咒 提交于 2019-11-26 21:32:05
问题 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

Number of days between two dates - ANSI SQL

亡梦爱人 提交于 2019-11-26 21:27:39
问题 I need a way to determine the number of days between two dates in SQL. Answer must be in ANSI SQL. 回答1: 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

AutoIncrement fields on databases without autoincrement field

邮差的信 提交于 2019-11-26 20:16:15
问题 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

How to rewrite IS DISTINCT FROM and IS NOT DISTINCT FROM?

二次信任 提交于 2019-11-26 20:07:49
How do you rewrite expressions containing the standard IS DISTINCT FROM and IS NOT DISTINCT FROM operators in SQL implementations such as Microsoft SQL Server 2008R2 that do not support them? The IS DISTINCT FROM predicate was introduced as feature T151 of SQL:1999, and its readable negation, IS NOT DISTINCT FROM , was added as feature T152 of SQL:2003. The purpose of these predicates is to guarantee that the result of comparing two values is either True or False , never Unknown . These predicates work with any comparable type (including rows, arrays and multisets) making it rather complicated

What does SQL Select symbol || mean?

戏子无情 提交于 2019-11-26 18:23:14
问题 What does || do in SQL? SELECT 'a' || ',' || 'b' AS letter 回答1: || 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

mysql - quote numbers or not?

点点圈 提交于 2019-11-26 16:33:52
For example - I create database and a table from cli and insert some data: CREATE DATABASE testdb CHARACTER SET 'utf8' COLLATE 'utf8_general_ci'; USE testdb; CREATE TABLE test (id INT, str VARCHAR(100)) TYPE=innodb CHARACTER SET 'utf8' COLLATE 'utf8_general_ci'; INSERT INTO test VALUES (9, 'some string'); Now I can do this and these examples do work (so - quotes don't affect anything it seems): SELECT * FROM test WHERE id = '9'; INSERT INTO test VALUES ('11', 'some string'); So - in these examples I've selected a row by a string that actually stored as INT in mysql and then I inserted a string

Is there an ANSI SQL alternative to the MYSQL LIMIT keyword?

无人久伴 提交于 2019-11-26 15:22:57
Is there an ANSI SQL alternative to the MYSQL LIMIT keyword? The LIMIT keyword limits the number of rows returned by a SELECT e.g: SELECT * FROM People WHERE Age > 18 LIMIT 2; returns 2 rows. SELECT * FROM People WHERE Age > 18 LIMIT 10, 2; returns 2 rows after the first 10. jle this shows the different ways: -- DB2 select * from table fetch first 10 rows only -- Informix select first 10 * from table -- Microsoft SQL Server and Access select top 10 * from table -- MySQL and PostgreSQL select * from table limit 10 -- Oracle select * from (select * from table) where rownum <= 10 Not in SQL:1999.

ANSI SQL Manual

£可爱£侵袭症+ 提交于 2019-11-26 15:19:29
问题 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.