INTERSECT, MINUS
am 16.10.2011 13:42:36 von legrega
WHat is wring with the following three sentences?
SELECT p.name, p.gender, e.pizza FROM Person p, Eats e WHERE p.name =3D
e.name AND p.gender =3D 'female' AND (e.pizza =3D 'mushroom')
INTERSECT
SELECT p.name, p.gender, e.pizza FROM Person p, Eats e WHERE p.name =3D
e.name AND p.gender =3D 'female' AND (e.pizza =3D 'pepperoni');
SELECT * FROM Person MINUS SELECT * FROM Person WHERE name=3D'Amy';
mysql> SELECT name FROM Person MINUS SELECT name FROM Person WHERE Person.a=
ge <
18;
I've tried my first time sets and am not sure where is the problem,
I've tried to google but when translating to my db it just doesn't
work,
You can download the create db sql here:
http://s3.amazonaws.com/dbclass-resources/docs/pizza.sql
â¥â¥â=A5 When the sun rises I receive and when it sets I=
forgive! â¥â¥â=A5
Ëâ=A5 -> http://moj.skavt.net/gleskovs/ <- â=A5 Always, Greg=
a Leskovšek
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=3Dgcdmg-mysql-2@m.gmane.o rg
Re: INTERSECT, MINUS
am 16.10.2011 14:06:09 von sureshkumarilu
--20cf30363b7dd7e22d04af695064
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Hi,
EXISTS function provides a simple way to find intersection between tables
(INTERSECT operator from relational model).
If we have table1 and table2, both having id and value columns, the
intersection could be calculated like this:
SELECT * FROM table1 WHERE EXISTS(SELECT * FROM table2 WHERE table1.id=3D
table2.id AND table1.value=3Dtable2.value)
For more details on intersect and minus, check this blog -
http://www.bitbybit.dk/carsten/blog/?p=3D71
Thanks
Suresh Kuna
On Sun, Oct 16, 2011 at 5:12 PM, Grega Leskovšek w=
rote:
> WHat is wring with the following three sentences?
>
> SELECT p.name, p.gender, e.pizza FROM Person p, Eats e WHERE p.name =3D
> e.name AND p.gender =3D 'female' AND (e.pizza =3D 'mushroom')
> INTERSECT
> SELECT p.name, p.gender, e.pizza FROM Person p, Eats e WHERE p.name =3D
> e.name AND p.gender =3D 'female' AND (e.pizza =3D 'pepperoni');
>
>
> SELECT * FROM Person MINUS SELECT * FROM Person WHERE name=3D'Amy';
>
>
> mysql> SELECT name FROM Person MINUS SELECT name FROM Person WHERE
> Person.age <
> 18;
>
> I've tried my first time sets and am not sure where is the problem,
> I've tried to google but when translating to my db it just doesn't
> work,
> You can download the create db sql here:
> http://s3.amazonaws.com/dbclass-resources/docs/pizza.sql
>
> â¥â¥â=A5 When the sun rises I receive and when it sets=
I forgive! â¥â¥â=A5
> Ëâ=A5 -> http://moj.skavt.net/gleskovs/ <- â=A5 Always, Gr=
ega Leskovšek
>
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe:
> http://lists.mysql.com/mysql?unsub=3Dsureshkumarilu@gmail.co m
>
>
--=20
Thanks
Suresh Kuna
MySQL DBA
--20cf30363b7dd7e22d04af695064--