![]() | |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Suppose I have two tables (A and B) with identical structures. |
|
I want to obtain the recordset containing all records that ARE in A and are NOT in B. A = {1 2 3 4 5 6 7 8 9 10} B = {2 4 6 8 10} |
|
then A & \B = {1 3 5 7 9} Right? Is this not a basic SQL query? |
#3
| |||
| |||
|
|
Suppose I have two tables (A and B) with identical structures. I want to obtain the recordset containing all records that ARE in A and are NOT in B. * A = {1 2 3 4 5 6 7 8 9 10} * B = {2 4 6 8 10} then * A & \B = {1 3 5 7 9} Right? Is this not a basic SQL query? Is the syntax "A-B" or "A\B"? |
#4
| |||
| |||
|
|
I never really understould why one should have to type: select * from T instead of just T |
#5
| |||
| |||
|
|
Fortunately, it's one that has been addressed in PostgreSQL at least: The command TABLE name is completely equivalent to SELECT * FROM name I don't have access to the SQL standard specification. Can someone show an online reference for whether the ‘TABLE’ statement is standard? |
#6
| |||
| |||
|
|
Prof Wonmug<wonmug@e.mcc> writes: Suppose I have two tables (A and B) with identical structures. CREATE TABLE a ( foo INTEGER, PRIMARY KEY (foo) ); CREATE TABLE b ( foo INTEGER, PRIMARY KEY (foo) ); I want to obtain the recordset containing all records that ARE in A and are NOT in B. A = {1 2 3 4 5 6 7 8 9 10} B = {2 4 6 8 10} INSERT INTO a (foo) VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10); INSERT INTO b (foo) VALUES (2), (4), (6), (8), (10); then A& \B = {1 3 5 7 9} Right? Is this not a basic SQL query? You want the NOT IN operator of the WHERE clause. First, determine which values of foo you *don't* want: SELECT foo FROM a NATURAL JOIN b ; foo ----- 2 4 6 8 10 (5 rows) Then, select rows from a where foo is not in the unwanted value set: SELECT foo FROM a WHERE foo NOT IN ( SELECT foo FROM a NATURAL JOIN b ) ; foo ----- 1 3 5 7 9 (5 rows) |
#7
| |||
| |||
|
|
Ben Finney wrote on 17.01.2010 07:01: Fortunately, it's one that has been addressed in PostgreSQL at least: * * * The command * * * TABLE name * * * is completely equivalent to * * * SELECT * FROM name I don't have access to the SQL standard specification. Can someone show an online reference for whether the TABLE statement is standard? I found the following in the SQL2003 foundation: The <explicit table TABLE <table or query name is equivalent to the <query expression ( SELECT * FROM <table or query name> ) So it seems that this is indeed part of the standard (although Postgres seems to the only DBMS implementing that as far as I know) |
#8
| |||
| |||
|
|
select foo from A EXCEPT select foo from B |
|
Some dbms use the keyword MINUS instead of EXCEPT. You can also use predicates like: not exists not in |
#9
| |||
| |||
|
|
On Jan 17, 11:16*am, Thomas Kellerer <OTPXDAJCS... (AT) spammotel (DOT) com wrote: Ben Finney wrote on 17.01.2010 07:01: Fortunately, it's one that has been addressed in PostgreSQL at least: * * * The command * * * TABLE name * * * is completely equivalent to * * * SELECT * FROM name I don't have access to the SQL standard specification. Can someone show an online reference for whether the TABLE statement is standard? I found the following in the SQL2003 foundation: The <explicit table TABLE <table or query name is equivalent to the <query expression ( SELECT * FROM <table or query name> ) So it seems that this is indeed part of the standard (although Postgres seems to the only DBMS implementing that as far as I k now) That's interesting and new to me. I checked with Mimers sql-validator and it confirms it: http://developer.mimer.com/validator...dex.tml#parser Result: The following feature outside Core SQL-99 is used: F661, "Simple tables" |
#10
| |||
| |||
|
![]() |
| Thread Tools | |
| Display Modes | |
| |