![]() | |
#11
| |||
| |||
|
|
I wonder what the odds are that we will get the possibility to specify a subset of columns |
|
as in: table t(c_1, c_3, c_n) |
|
and even table t(c_1, c_3, c_n) extend (...) |
#12
| |||
| |||
|
|
On 17.01.2010 03:53, Ben Finney wrote: 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) I am not sure it is a good idea to always join - especially if A is large. For me the most natural solution would involve NOT EXISTS: |
|
SELECT foo FROM A WHERE NOT EXISTS ( SELECT foo FROM B WHERE B.foo = A.foo ) |
#13
| |||
| |||
|
|
select foo from A EXCEPT select foo from B EXCEPT: that's neat, like the opposite of UNION. Some dbms use the keyword MINUS instead of EXCEPT. You can also use predicates like: not exists not in you can also use a join. select a.foo from a left outer join b on a.foo=b.foo where b.foo is null; |
#14
| |||
| |||
|
|
Are all of these commands supported by MySQL? |
|
Are all of these commands supported in mySQL? |
#15
| |||
| |||
|
|
Prof Wonmug <wonmug@e.mcc> writes: Are all of these commands supported by MySQL? Prof Wonmug <wonmug@e.mcc> writes: Are all of these commands supported in mySQL? What happens when you try it on your installation of MySQL? |
#16
| |||
| |||
|
|
On Tue, 19 Jan 2010 08:37:02 +1100, Ben Finney bignose+hates-s... (AT) benfinney (DOT) id.au> wrote: Prof Wonmug <won...@e.mcc> writes: Are all of these commands supported by MySQL? Prof Wonmug <won...@e.mcc> writes: Are all of these commands supported in mySQL? What happens when you try it on your installation of MySQL? I don't have an installation of MySQL or anything else (except Access). I am trying to determine which database system to use. I was hoping that a MySQL expert could tell me. |
#17
| |||
| |||
|
|
On 18 Jan 2010 09:29:01 GMT, Jasen Betts <jasen (AT) xnet (DOT) co.nz> wrote: select foo from A EXCEPT select foo from B EXCEPT: that's neat, like the opposite of UNION. Some dbms use the keyword MINUS instead of EXCEPT. You can also use predicates like: not exists not in you can also use a join. select a.foo from a left outer join b on a.foo=b.foo where b.foo is null; Are all of these commands supported in mySQL? |
![]() |
| Thread Tools | |
| Display Modes | |
| |