$B650i%5!<%P!<$N%Z!<%8(B
$B%*%s%i%$%s%F%-%9%HL\
$B%7%9%F%`%W%m%0%i%_%s%01i=,(B

MySQL (3)

MySQL$B!J4X?tA`:n$H7k9gA`:n!K(B

1. $B4X?t$rMxMQ$7$?8!:w(B

a) $B%G!<%?7o?t$r5a$a$k(B

$B%F!<%V%k$KEPO?$5$l$F$$$k%G!<%?$N7o?t$r5a$a$k$?$a$K$O!"(B COUNT$B4X?t$rMxMQ$9$k!#(BCOUNT$B4X?t$N0z?t$K(B* ($B%"%9%?%j%9%/!K$r(B $BM?$($k$H!"%F!<%V%k$KEPO?$5$l$F$$$k$9$Y$F$N%G!<%?$N7o?t$r(B $B5a$a$k!#%3%^%s%I$N7A<0$O

mysql> select count(*) from $B%F!<%V%kL>(B;

$B0J2<$G$O!"(Bfruit$B%F!<%V%k$N%G!<%?7o?t$r5a$a$k%3%^%s%I$H$=$N(B $B

fruit$B%F!<%V%k(B

no nameprice
1apple100
2grape130
3banana90
4peach150
5meron600

mysql> select count(*) from fruit;
+----------+
| count(*) |
+----------+
|        5 |
+----------+
1 row in set (0.00 sec)

mysql>

b) $B=87W$r$*$3$J$&(B

$B>r7o$K3:Ev$9$k$9$Y$F$N%l%3!<%I$KBP$7$F!"9g7W$dJ?6QCM$J$I$N(B $B=87W$r$*$3$J$&>l9g$K$O!"=87WMQ$N4X?t(B(SUM, AVG, MAX, MIN)$B$rMxMQ$9$k!#(B $B$=$N>l9g$N%3%^%s%I$N7A<0$O

$B9g7W!'!!(Bmysql> select sum($B%U%#!<%k%IL>(B) from $B%F!<%V%kL>(B where $B>r7o<0(B;

$BJ?6Q!'!!(Bmysql> select avg($B%U%#!<%k%IL>(B) from $B%F!<%V%kL>(B where $B>r7o<0(B;

$B:GBgCM!'!!(Bmysql> select max($B%U%#!<%k%IL>(B) from $B%F!<%V%kL>(B where $B>r7o<0(B;

$B:G>.CM!'!!(Bmysql> select min($B%U%#!<%k%IL>(B) from $B%F!<%V%kL>(B where $B>r7o<0(B;

$B>e5-$N=87W4X?t$rMQ$$$F!"(Bfruit$B%F!<%V%k$KBP$9$k(Bprice$B$NJ?6QCM$r(B $B5a$a$F$_$h$&!#I,MW$J%3%^%s%I$H$=$N

mysql> select avg(price) from fruit;
+------------+
| avg(price) |
+------------+
|   214.0000 |
+------------+
1 row in set (0.00 sec)

mysql>

$BF1MM$K!"=87W4X?t$rMQ$$$F!"(Bfruit$B%F!<%V%k$K$*$1$k(Bprice$B$N(B $B:G>.CM$r5a$a$F$_$h$&!#I,MW$H$J$k%3%^%s%I$H$=$N

mysql> select min(price) from fruit;
+------------+
| min(price) |
+------------+
|         90 |
+------------+
1 row in set (0.00 sec)

mysql>

2. $B%F!<%V%k$N7k9g(B

SQL$BJ8$rMQ$$$FJ#?t$N%F!<%V%k$r7k9g$9$kJ}K!$K$D$$$F(B $B@bL@$9$k!#%F!<%V%k$N7k9gJ}K!$O!"Bg$-$/$o$1$F#4$D$K(B $BJ,N`$G$-$k!#(B

$B-5(B. $BFbIt7k9g(B

$BFbIt7k9g$O!":G$bMxMQIQEY$,9b$$!#(B $B#2$D$N%F!<%V%k!J7k9g85$N%F!<%V%k$H7k9g@h$N%F!<%V%k!K(B $B$K$*$$$F!"APJ}$K%G!<%?$,B8:_$9$k%l%3!<%I$r7k9g$9$k!#(B $B$J$*!"7k9g$G$-$J$+$C$?%G!<%?$O!"7k9g7k2L$KH?1G$5$;$J$$!#(B $B$?$H$($P!"#2$D$N%F!<%V%k$KJ,;6$7$F$$$kEPO?$5$l$F$$$k(B $B%G!<%?$r$^$H$a$FMxMQ$9$k>l9g$K!"FbIt7k9g$OMQ$$$i$l$k!#(B

[INNER JOIN$B6g$NMxMQ(B]

SELECT$BJ8$H(BFROM$B6g$G!"7k9gBP>]$N%F!<%V%k$dCj=P$9$k(B $B%U%#!<%k%IL>$r;XDj$9$k!#FbIt7k9g$9$k>l9g$K$O!"7k9g$9$k(B $B%F!<%V%k$r(BINNER JOIN$B6g$G7k9g85$H7k9g@h$K$o$1$F;XDj$9$k!#(B $B0J2<$N(BSQL$BJ8$G$O!"7k9g>r7o$H$7$F!"F1$8L>A0$N%U%#!<%k%IL>$r(B $B%-!<$H$7$F7k9g$7$F$$$k!#(B

mysql> select $B%U%#!<%k%IL>#1(B, $B%U%#!<%k%IL>#2(B, .... from $B%F!<%V%kL>#1(B
inner join $B%F!<%V%kL>#2(B 
$B!!!!!!(Bon $B7k9g>r7o!J%F!<%V%kL>#1(B.$B%U%#!<%k%IL>#3(B = $B%F!<%V%kL>#2(B.$B%U%#!<%k%IL>#3!K(B;

$B$^$:!"@bL@$N$?$a$K#2$D$N%F!<%V%k(B(syohin_tbl$B$H(Bhanbai_tbl)$B$r(B $B:n@.$9$k!#$=$l$>$l$N%F!<%V%k$N9=B$$O0J2<$N$H$*$j$G$"$k!#(B

syohin_tbl$B%F!<%V%k$N9=B$(B

$BNsL>(B $B%G!<%?7?(BNOT NULL
syohincode VARCHAR(10)NOT NULL
bunruicodeVARCHAR(5)
syohinnameVARCHAR(10)

syohin_tbl$B%F!<%V%k(B

syohincodebunruicodesyohinname
A01001A01apple
G02002G02grape
B03003B03banana
P01004P01peach
M02005M02meron

hanbai_tbl$B%F!<%V%k$N9=B$(B

$BNsL>(B $B%G!<%?7?(BNOT NULL
hanbaicode VARCHAR(10)NOT NULL
kokyakucodeVARCHAR(5)
syohincodeVARCHAR(100)
priceINT(10)
hanbaibiDATE

hanbai_tbl$B%F!<%V%k(B

hanbaicodekokyakucodesyohincodepricehanbaibi
H010012121G020021302003-04-12
H010033211B03003902003-04-29
H010051001A010011002003-05-01
H010100072M020056002003-05-03
H010200002P010041502003-05-10

$BN>J}$N%F!<%V%k$G$O!">&IJ$HHNGd&IJ$HHNGdJ}$r$G4XO"IU$1$i$l$F$$$k(B $B$N$G!"N>&IJ$HHNGd$+$i$J$k%F!<%V%k$r SQL$BJ8$r;H$C$F!">e5-$N%F!<%V%k7k9g$r$*$3$J$C$F$_$h$&!#(B $B$3$N%F!<%V%k7k9g$KI,MW$J%3%^%s%I$H$=$N

mysql> select * from syohin_tbl inner join hanbai_tbl
              on syohin_tbl.syohincode = hanbai_tbl.syohincode;
+------------+------------+------------+------------+-------------+------------+-------+------------+
| syohincode | bunruicode | syohinname | hanbaicode | kokyakucode | syohincode | price | hanbaibi   |
+------------+------------+------------+------------+-------------+------------+-------+------------+
| G02002     | G02        | grape      | H01001     | 2121        | G02002     |   130 | 2003-04-12 |
| B03003     | B03        | banana     | H01003     | 3211        | B03003     |    90 | 2003-04-29 |
| A01001     | A01        | apple      | H01005     | 1001        | A01001     |   100 | 2003-05-01 |
| M02005     | M02        | meron      | H01010     | 0072        | M02005     |   600 | 2003-05-03 |
| P01004     | P01        | peach      | H01020     | 0002        | P01004     |   150 | 2003-05-10 |
+------------+------------+------------+------------+-------------+------------+-------+------------+
5 rows in set (0.00 sec)

mysql>

$B>e5-$NNc$G$O!"%U%#!<%k%I$r;XDj$7$J$$$?$a$9$Y$F$N%U%#!<%k%I(B $B$r4^$s$@%F!<%V%k$,:n@.!"I=<($5$l$F$$$k!#(B

$B$r;XDj$7$F!"F1$8%U%#!<%k%I$,=EJ#$7$J$$$h$&(B $B%F!<%V%k$r:n@.!"I=<($7$F$_$h$&!#(B

mysql> select syohin_tbl.syohincode, syohin_tbl.bunruicode, syohin_tbl.syohinname, 
              hanbai_tbl.hanbaicode, hanbai_tbl.kokyakucode, hanbai_tbl.price, hanbai_tbl.hanbaibi
              from syohin_tbl inner join hanbai_tbl
              on syohin_tbl.syohincode = hanbai_tbl.syohincode;

+------------+------------+------------+------------+-------------+-------+------------+
| syohincode | bunruicode | syohinname | hanbaicode | kokyakucode | price | hanbaibi   |
+------------+------------+------------+------------+-------------+-------+------------+
| G02002     | G02        | grape      | H01001     | 2121        |   130 | 2003-04-12 |
| B03003     | B03        | banana     | H01003     | 3211        |    90 | 2003-04-29 |
| A01001     | A01        | apple      | H01005     | 1001        |   100 | 2003-05-01 |
| M02005     | M02        | meron      | H01010     | 0072        |   600 | 2003-05-03 |
| P01004     | P01        | peach      | H01020     | 0002        |   150 | 2003-05-10 |
+------------+------------+------------+------------+-------------+-------+------------+
5 rows in set (0.00 sec)

mysql>

$B$5$i$K!"%U%#!<%k%IL>$rA*Br!&;XDj$7$?%F!<%V%k$r:n@.$9$k$H(B $B0J2<$N$h$&$K$J$k!#(B

mysql> select syohin_tbl.syohinname, hanbai_tbl.kokyakucode, hanbai_tbl.hanbaibi, hanbai_tbl.price 
              from syohin_tbl inner join hanbai_tbl
              on syohin_tbl.syohincode = hanbai_tbl.syohincode;

+------------+-------------+------------+-------+
| syohinname | kokyakucode | hanbaibi   | price |
+------------+-------------+------------+-------+
| grape      | 2121        | 2003-04-12 |   130 |
| banana     | 3211        | 2003-04-29 |    90 |
| apple      | 1001        | 2003-05-01 |   100 |
| meron      | 0072        | 2003-05-03 |   600 |
| peach      | 0002        | 2003-05-10 |   150 |
+------------+-------------+------------+-------+
5 rows in set (0.00 sec)

mysql> 

[WHERE$B6g$NMxMQ(B]

$B>e5-$N(BINNER JOIN$B6g$K$h$kFbIt7k9g$HF1MM$JA`:n$r0J2<$N(BWHERE$B6g$r(B $B;H$C$F$*$3$J$&$3$H$,$G$-$k!#(B WHERE$B6g$K$h$kFbIt7k9g$G$O!"(BSELECT$BJ8$r;H$$!"7k9g@h$N%F!<%V%kL>$H(B INNER JOIN$B6g$N>r7o<0$r5-=R$9$k!#(BSELECT$BJ8$N;H$C$?9=J8$O!"0J2<$N(B $B$h$&$K$J$k!#(B

mysql> select $B%U%#!<%k%IL>#1(B, $B%U%#!<%k%IL>#2(B, .... from $B%F!<%V%kL>#1(B, $B%F!<%V%kL>#2(B where $B7k9g>r7o!J%F!<%V%kL>#1(B.$B%U%#!<%k%IL>#3(B = $B%F!<%V%kL>#2(B.$B%U%#!<%k%IL>#3!K(B;

INNER JOIN$B6g$NNc$rMQ$$$F!"FbIt7k9g$K$h$k%F!<%V%k$r:n@.$7$F$_$h$&!#(B $B$^$:!"$9$Y$F$N%U%#!<%k%IL>$r4^$`%F!<%V%k$r:n@.!"I=<($7$F$_$h$&!#(B

mysql> select * from syohin_tbl, hanbai_tbl 
              where syohin_tbl.syohincode = hanbai_tbl.syohincode;

+------------+------------+------------+------------+-------------+------------+-------+------------+
| syohincode | bunruicode | syohinname | hanbaicode | kokyakucode | syohincode | price | hanbaibi   |
+------------+------------+------------+------------+-------------+------------+-------+------------+
| G02002     | G02        | grape      | H01001     | 2121        | G02002     |   130 | 2003-04-12 |
| B03003     | B03        | banana     | H01003     | 3211        | B03003     |    90 | 2003-04-29 |
| A01001     | A01        | apple      | H01005     | 1001        | A01001     |   100 | 2003-05-01 |
| M02005     | M02        | meron      | H01010     | 0072        | M02005     |   600 | 2003-05-03 |
| P01004     | P01        | peach      | H01020     | 0002        | P01004     |   150 | 2003-05-10 |
+------------+------------+------------+------------+-------------+------------+-------+------------+
5 rows in set (0.00 sec)

mysql>

$B>e5-$NNc$G$O!"%U%#!<%k%I$r;XDj$7$J$$$?$a$9$Y$F$N%U%#!<%k%I$r4^$s$@%F!<%V%k$,:n@.!"I=<($5$l$F$$$k!#(B

$B$r;XDj$7$F!"F1$8%U%#!<%k%I$,=EJ#$7$J$$$h$&%F!<%V%k$r:n@.!"I=<($7$F$_$h$&!#(B

mysql> select syohin_tbl.syohincode, syohin_tbl.bunruicode, syohin_tbl.syohinname, 
              hanbai_tbl.hanbaicode, hanbai_tbl.kokyakucode, hanbai_tbl.price, hanbai_tbl.hanbaibi
              from syohin_tbl, hanbai_tbl 
              where syohin_tbl.syohincode = hanbai_tbl.syohincode;

+------------+------------+------------+------------+-------------+-------+------------+
| syohincode | bunruicode | syohinname | hanbaicode | kokyakucode | price | hanbaibi   |
+------------+------------+------------+------------+-------------+-------+------------+
| G02002     | G02        | grape      | H01001     | 2121        |   130 | 2003-04-12 |
| B03003     | B03        | banana     | H01003     | 3211        |    90 | 2003-04-29 |
| A01001     | A01        | apple      | H01005     | 1001        |   100 | 2003-05-01 |
| M02005     | M02        | meron      | H01010     | 0072        |   600 | 2003-05-03 |
| P01004     | P01        | peach      | H01020     | 0002        |   150 | 2003-05-10 |
+------------+------------+------------+------------+-------------+-------+------------+

5 rows in set (0.00 sec)
mysql>

$B$5$i$K!"%U%#!<%k%IL>$rA*Br!&;XDj$7$?%F!<%V%k$r:n@.$9$k$H0J2<$N$h$&$K$J$k!#(B

mysql> select syohin_tbl.syohinname, hanbai_tbl.kokyakucode, hanbai_tbl.hanbaibi, hanbai_tbl.price from syohin_tbl, hanbai_tbl
              where syohin_tbl.syohincode = hanbai_tbl.syohincode;

+------------+-------------+------------+-------+
| syohinname | kokyakucode | hanbaibi   | price |
+------------+-------------+------------+-------+
| grape      | 2121        | 2003-04-12 |   130 |
| banana     | 3211        | 2003-04-29 |    90 |
| apple      | 1001        | 2003-05-01 |   100 |
| meron      | 0072        | 2003-05-03 |   600 |
| peach      | 0002        | 2003-05-10 |   150 |
+------------+-------------+------------+-------+
5 rows in set (0.00 sec)

mysql> 

$B-6(B. $B30It7k9g(B

$B30It7k9g$G$O!"7k9g@h$N%F!<%V%k$K3:Ev$9$k%G!<%?$,$J$/$F$b!"(B $B7k2L$r5a$a$F%F!<%V%k$r:n@.$G$-$k!#(B $B30It7k9g$K$O!"0J2<$N#2$D$,$"$k!#(B

$B30It7k9g$O!":81&%F!<%V%k$N7k9gJ}K!$K$h$j7k9g7k2L$,0[$J$k(B $B$3$H$KCm0U$,I,MW$G$"$k!#:8B&$N%F!<%V%k$rM%@h$9$k30It7k9g$r(B $B:830It7k9g$H$$$&!#0lJ}!"1&B&$N%F!<%V%k$rM%@h$9$k30It7k9g$r(B $B1&30It7k9g$H$$$&!#:830It7k9g$O!"7k9g@h$N1&B&$K$"$k%F!<%V%k(B $B$K3:Ev$9$k%G!<%?$,$J$/$F$b!"(BNULL$BCM$GCV$-49$($i$l$?%G!<%?$r(B $B4^$`%F!<%V%k$,@8@.$5$l$k!#(B

[$B:830It7k9g(B]

LEFT JOIN$B6g$r;XDj$7$F:830It7k9g$r$*$3$J$&(BSQL$B9=J8$O!"(B $B

mysql> select $B%U%#!<%k%IL>#1(B, $B%U%#!<%k%IL>#2(B, .... from $B%F!<%V%kL>#1(B
             left join $B%F!<%V%kL>#2(B on $B7k9g>r7o!J%F!<%V%kL>#1(B.$B%U%#!<%k%IL>#3(B = $B%F!<%V%kL>#2(B.$B%U%#!<%k%IL>#3!K(B;

$B0J2<$G$O!"?7$?$J%F!<%V%k$H$7$F!"0J2<$N$h$&$J(Bsyohin_tbl1 $B%F!<%V%k$rDj5A$9$k!#%F!<%V%k$N9=B$$O!"(Bsyohin_tbl$B%F!<%V%k(B $B$HF1MM$G$"$k!#(B

syohin_tbl1$B%F!<%V%k$N9=B$(B

$BNsL>(B $B%G!<%?7?(BNOT NULL
syohincode VARCHAR(10)NOT NULL
bunruicodeVARCHAR(5)
syohinnameVARCHAR(100)

syohin_tbl1$B%F!<%V%k(B

syohincodebunruicodesyohinname
A01001A01apple
G02002G02grape
B03003B03banana
X04001X04ice_cream
Y02007Y02chocolate

LEFT JOIN$B6g$r;XDj$7$?:830It7k9g$G$O!"(Bsyohin_tbl1$B%F!<%V%k(B $B$H(Bhanbai_tbl$B%F!<%V%k$K(B $B$*$$$F!"(Bsyohin_tbl1$B%F!<%V%k$KEPO?$5$l$F$$$k%l%3!<%I$r(B $BM%@h$7$F(Bsyohincode$B%U%#!<%k%IL>$NCM$,Ey$7$$%l%3!<%IF1;N(B $B$r7k9g$9$k!#(B

$B$r4^$`%F!<%V%k$N:n@.!&

mysql> select * from syohin_tbl1 left join hanbai_tbl
              on syohin_tbl1.syohincode = hanbai_tbl.syohincode;
+------------+------------+------------+------------+-------------+------------+-------+------------+
| syohincode | bunruicode | syohinname | hanbaicode | kokyakucode | syohincode | price | hanbaibi   |
+------------+------------+------------+------------+-------------+------------+-------+------------+
| A01001     | A01        | apple      | H01005     | 1001        | A01001     |   100 | 2003-05-01 |
| G02002     | G02        | grape      | H01001     | 2121        | G02002     |   130 | 2003-04-12 |
| B03003     | B03        | banana     | H01003     | 3211        | B03003     |    90 | 2003-04-29 |
| X04001     | X04        | ice_cream  | NULL       | NULL        | NULL       |  NULL | NULL       |
| Y02007     | Y02        | chocolate  | NULL       | NULL        | NULL       |  NULL | NULL       |
+------------+------------+------------+------------+-------------+------------+-------+------------+
5 rows in set (0.00 sec)

mysql> 

$B%U%#!<%k%IL>$r;XDj$7$F!"F1$8%U%#!<%k%I$,=EJ#$7$J$$$h$&%F!<%V%k$r:n@.!"I=<($7$F$_$k$H!"

mysql> select syohin_tbl1.syohincode, syohin_tbl1.bunruicode, syohin_tbl1.syohinname, 
              hanbai_tbl.hanbaicode, hanbai_tbl.kokyakucode, hanbai_tbl.price, 
              hanbai_tbl.hanbaibi from syohin_tbl1 left join hanbai_tbl
              on syohin_tbl1.syohincode = hanbai_tbl.syohincode;

+------------+------------+------------+------------+-------------+-------+------------+
| syohincode | bunruicode | syohinname | hanbaicode | kokyakucode | price | hanbaibi   |
+------------+------------+------------+------------+-------------+-------+------------+
| A01001     | A01        | apple      | H01005     | 1001        |   100 | 2003-05-01 |
| G02002     | G02        | grape      | H01001     | 2121        |   130 | 2003-04-12 |
| B03003     | B03        | banana     | H01003     | 3211        |    90 | 2003-04-29 |
| X04001     | X04        | ice_cream  | NULL       | NULL        |  NULL | NULL       |
| Y02007     | Y02        | chocolate  | NULL       | NULL        |  NULL | NULL       |
+------------+------------+------------+------------+-------------+-------+------------+
5 rows in set (0.00 sec)

mysql> 

$B$5$i$K!"%U%#!<%k%IL>$rA*Br!&;XDj$7$?%F!<%V%k$r:n@.$9$k$H0J2<$N$h$&$K$J$k!#(B

mysql> select syohin_tbl1.syohinname, hanbai_tbl.kokyakucode, hanbai_tbl.hanbaibi, hanbai_tbl.price 
              from syohin_tbl1 left join hanbai_tbl
              on syohin_tbl1.syohincode = hanbai_tbl.syohincode;
+------------+-------------+------------+-------+
| syohinname | kokyakucode | hanbaibi   | price |
+------------+-------------+------------+-------+
| apple      | 1001        | 2003-05-01 |   100 |
| grape      | 2121        | 2003-04-12 |   130 |
| banana     | 3211        | 2003-04-29 |    90 |
| ice_cream  | NULL        | NULL       |  NULL |
| chocolate  | NULL        | NULL       |  NULL |
+------------+-------------+------------+-------+
5 rows in set (0.01 sec)

mysql> 

[$B1&30It7k9g(B]

$B1&30It7k9g$G$O:830It7k9g$H$O5U$K!"1&B&$N%F!<%V%k$rM%@h$7$F7k9g(B $B$9$k!#6qBNE*$K$$$&$H!":8B&$K$"$k%F!<%V%kL>(B1$B$H1&B&$K$"$k%F!<%V%kL>(B2 $B$N%l%3!<%I$G!"%F!<%V%kL>(B2$B$KEPO?$5$l$F$$$k%l%3!<%I$rM%@h$7$F!"7k9g(B $B>r7o$rK~B-$9$k%l%3!<%IF1;N$r7k9g$7$F%F!<%V%k$r:n@.$9$k!#(B

$B$3$l$r(BRIGHT JOIN$B6g$r;XDj$7$F1&30It7k9g$r$*$3$J$&$?$a$K$O!"(B $B

mysql> select $B%U%#!<%k%IL>#1(B, $B%U%#!<%k%IL>#2(B, .... from $B%F!<%V%kL>#1(B
             right join $B%F!<%V%kL>#2(B on $B7k9g>r7o!J%F!<%V%kL>#1(B.$B%U%#!<%k%IL>#3(B = $B%F!<%V%kL>#2(B.$B%U%#!<%k%IL>#3!K(B;

$B$r4^$`%F!<%V%k$N:n@.!&

mysql> select * from syohin_tbl1 right join hanbai_tbl
              on syohin_tbl1.syohincode = hanbai_tbl.syohincode;

+------------+------------+------------+------------+-------------+------------+-------+------------+
| syohincode | bunruicode | syohinname | hanbaicode | kokyakucode | syohincode | price | hanbaibi   |
+------------+------------+------------+------------+-------------+------------+-------+------------+
| G02002     | G02        | grape      | H01001     | 2121        | G02002     |   130 | 2003-04-12 |
| B03003     | B03        | banana     | H01003     | 3211        | B03003     |    90 | 2003-04-29 |
| A01001     | A01        | apple      | H01005     | 1001        | A01001     |   100 | 2003-05-01 |
| NULL       | NULL       | NULL       | H01010     | 0072        | M02005     |   600 | 2003-05-03 |
| NULL       | NULL       | NULL       | H01020     | 0002        | P01004     |   150 | 2003-05-10 |
+------------+------------+------------+------------+-------------+------------+-------+------------+
5 rows in set (0.00 sec)

mysql> 

$B%U%#!<%k%IL>$r;XDj$7$F!"F1$8%U%#!<%k%I$,=EJ#$7$J$$$h$&%F!<%V%k$r:n@.!"I=<($7$F$_$k$H!"

mysql> select hanbai_tbl.syohincode, syohin_tbl1.bunruicode, syohin_tbl1.syohinname, 
              hanbai_tbl.hanbaicode, hanbai_tbl.kokyakucode, hanbai_tbl.price, 
              hanbai_tbl.hanbaibi from syohin_tbl1 right join hanbai_tbl
              on syohin_tbl1.syohincode = hanbai_tbl.syohincode;

+------------+------------+------------+------------+-------------+-------+------------+
| syohincode | bunruicode | syohinname | hanbaicode | kokyakucode | price | hanbaibi   |
+------------+------------+------------+------------+-------------+-------+------------+
| G02002     | G02        | grape      | H01001     | 2121        |   130 | 2003-04-12 |
| B03003     | B03        | banana     | H01003     | 3211        |    90 | 2003-04-29 |
| A01001     | A01        | apple      | H01005     | 1001        |   100 | 2003-05-01 |
| M02005     | NULL       | NULL       | H01010     | 0072        |   600 | 2003-05-03 |
| P01004     | NULL       | NULL       | H01020     | 0002        |   150 | 2003-05-10 |
+------------+------------+------------+------------+-------------+-------+------------+


5 rows in set (0.00 sec)

mysql> 

$B$5$i$K!"%U%#!<%k%IL>$rA*Br!&;XDj$7$?%F!<%V%k$r:n@.$9$k$H0J2<$N$h$&$K$J$k!#(B

mysql> select hanbai_tbl.syohincode, syohin_tbl1.syohinname, hanbai_tbl.kokyakucode, 
              hanbai_tbl.hanbaibi, hanbai_tbl.price 
              from syohin_tbl1 right join hanbai_tbl
              on syohin_tbl1.syohincode = hanbai_tbl.syohincode;

+------------+------------+-------------+------------+-------+
| syohincode | syohinname | kokyakucode | hanbaibi   | price |
+------------+------------+-------------+------------+-------+
| G02002     | grape      | 2121        | 2003-04-12 |   130 |
| B03003     | banana     | 3211        | 2003-04-29 |    90 |
| A01001     | apple      | 1001        | 2003-05-01 |   100 |
| M02005     | NULL       | 0072        | 2003-05-03 |   600 |
| P01004     | NULL       | 0002        | 2003-05-10 |   150 |
+------------+------------+-------------+------------+-------+

5 rows in set (0.00 sec)

mysql> 

$B-7(B. $B%f%K%*%s$K$h$k7k9g!!(B

$BFbIt7k9g$d30It7k9g$,%F!<%V%k$r:81&J}8~$K7k9g$5$;$k(B $B$b$N$G$"$k$N$KBP$7$F!"%f%K%*%s$O7k9g7k2L$r>e2 $B%f%K%*%s$K$h$k7k9g$r$*$3$J$&$K$O!"7k9g$9$k%F!<%V%kF1;N!"(B $B$^$?$O!"F1$8%U%#!<%k%IL>$r$b$D%F!<%V%k9=B$$G$"$k$3$H$,(B $BI,MW$G$"$k!#(B

$B%f%K%*%s$K$h$k7k9g$r$*$3$J$&$?$a$K!"#2$D$N%F!<%V%k$r%^!<%8%F!<%V%k(B $B5!G=(B(merge union)$B$r;H$C$F7k9g$9$k!#$^$:!"%^!<%8$5$l$?%l%3!<%I$r(B $B3JG<$9$k%F!<%V%k$r:n@.$7!" $B%f%K%*%s$K$h$k7k9g$G$O!" mysql> select * from $B%F!<%V%kL>#1(B union select * from $B%F!<%V%kL>#2(B;

$B]$H$9$k%F!<%V%k$O!"0J2<$N$h$&$J(Bshinamono_tbl1$B$H(B shinamono_tbl2$B$H$9$k!#(B

shinamono_tbl$B%F!<%V%k$N9=B$(B

$BNsL>(B $B%G!<%?7?(BNOT NULL
shinamonocode VARCHAR(10)NOT NULL
shinamonameVARCHAR(20)

shinamono_tbl1$B%F!<%V%k(B

shinamonocodeshinamononame
A001apple
A002orange
A003banana
A004grape

shinamono_tbl2$B%F!<%V%k(B

shinamonocodeshinamononame
B001tomato
B002cabbage
B003potato
B004corn

shinamono_tbl1$B$H(Bshinamono_tbl2$B$r%f%K%*%s$r;H$C$F7k9g$9$k$?$a$K$O!"(B $B0J2<$N(BSQL$B%3%^%s%I$,I,MW$K$J$k!#

mysql> select * from shinamono_tbl1 union select * from shinamono_tbl2;

+---------------+-------------+
| shinamonocode | shinamoname |
+---------------+-------------+
| A001          | apple       |
| A002          | orange      |
| A003          | banana      |
| A004          | grape       |
| B001          | tomato      |
| B002          | cabbage     |
| B003          | potato      |
| B004          | corn        |
+---------------+-------------+
8 rows in set (0.00 sec)

mysql> 

$B-8(B. $B<+8J7k9g(B

$B<+8J7k9g$G$O!"F1$8%F!<%V%kF1;N$r7k9g$9$k!#$?$@$7!"7k9g;~$K(B $B;XDj$9$k%-!<$H%U%#!<%k%IL>$,A4$/F1$8$K$J$C$F$7$^$&$N$G!"(B $BJLL>$r;XDj$9$k$J$I$NCm0U$,I,MW$H$J$k!#(B

$B<+8J7k9g$r$*$3$J$&(BSQL$BJ8$O!"0J2<$N$h$&$K$J$k!#(B

mysql> select $B%U%#!<%k%IL>#1(B, $B%U%#!<%k%IL>#2(B, .... from $B%F!<%V%kL>(B
as $BJLL>(B1, $B%F!<%V%kL>(B as $BJLL>(B2 where $B7k9g>r7o!JJLL>#1(B.$B%U%#!<%k%IL>(B = $BJLL>#2(B.$B%U%#!<%k%IL>!K(B;

$B

mysql> select * from shinamono_tbl1 as st1, shinamono_tbl1 as st2 
              where st1.shinamonocode = st2.shinamonocode;

+---------------+---------------+---------------+---------------+
| shinamonocode | shinamononame | shinamonocode | shinamononame |
+---------------+---------------+---------------+---------------+
| A001          | apple         | A001          | apple         |
| A002          | orange        | A002          | orange        |
| A003          | banana        | A003          | banana        |
| A004          | grape         | A004          | grapea        |
+---------------+---------------+---------------+---------------+
4 rows in set (0.00 sec)

mysql> 

$B-9(B. $B8r:97k9g!!(B

$B8r:97k9g$O!"#2$D$N%F!<%V%k$N$"$i$f$k%G!<%?F1;N$rAH$_9g$o$;$k(B $B7k9g$G$"$k!#7k9g8e$N%G!<%??t$,#2$D$N%F!<%V%k$N@Q$K$J$k$N$G!"(B $BF@$i$l$k7k2L$,KDBg$K$J$k$N$GCm0U$,I,MW$G$"$k!#(B

$B8r:97k9g$r$*$3$J$&$?$a$K$O!"

mysql> select $B%U%#!<%k%IL>#1(B, $B%U%#!<%k%IL>#2(B, .... from $B%F!<%V%kL>(B1, $B%F!<%V%kL>(B2;

$B8r:97k9g$O!"0J2<$N9=J8$G$bF1MM$JA`:n$K$h$j

mysql> select $B%U%#!<%k%IL>#1(B, $B%U%#!<%k%IL>#2(B, .... from $B%F!<%V%kL>(B1 cross  join  $B%F!<%V%kL>(B2;

$B

mysql> select * from shinamono_tbl1, shinamono_tbl2;

+---------------+---------------+---------------+---------------+
| shinamonocode | shinamononame | shinamonocode | shinamononame |
+---------------+---------------+---------------+---------------+
| A001          | apple         | B001          | tomato        |
| A002          | orange        | B001          | tomato        |
| A003          | banana        | B001          | tomato        |
| A004          | grape         | B001          | tomato        |
| A001          | apple         | B002          | cabbage       |
| A002          | orange        | B002          | cabbage       |
| A003          | banana        | B002          | cabbage       |
| A004          | grape         | B002          | cabbage       |
| A001          | apple         | B003          | potato        |
| A002          | orange        | B003          | potato        |
| A003          | banana        | B003          | potato        |
| A004          | grape         | B003          | potato        |
| A001          | apple         | B004          | corn          |
| A002          | orange        | B004          | corn          |
| A003          | banana        | B004          | corn          |
| A004          | grape         | B004          | corn          |
+---------------+---------------+---------------+---------------+
16 rows in set (0.00 sec)

mysql>

mysql> 

$BLdBj(B-0

$B>e5-$G@bL@$7$?%3%^%s%I$r$9$Y$F $BLdBj(B-1
fruit$B%F!<%V%k$+$i(Bprice$B%U%#!<%k%I$NCM$,(B100$B0J>e$N%G!<%?!J%l%3!<%I!K7o?t$r5a$a!"(B $BI=<($;$h!#(B

$BLdBj(B-2

fruit$B%F!<%V%k$+$i(Bprice$B%U%#!<%k%I$NCM$N9g7W$r5a$a!"(B $B$=$N7k2L$rI=<($;$h!#$=$N:]$KMQ$$$?%3%^%s%I$r<($9$3$H!#(B

$BLdBj(B-3

fruit$B%F!<%V%k$+$i(Bprice$B%U%#!<%k%I$NCM$NJ?6Q$r5a$a!"(B $B$=$N7k2L$rI=<($;$h!#$=$N:]$KMQ$$$?%3%^%s%I$r<($9$3$H!#(B

$BLdBj(B-4

fruit$B%F!<%V%k$+$i(Bprice$B%U%#!<%k%I$NCM$N:GBgCM$r5a$a!"(B $B$=$N7k2L$rI=<($;$h!#$=$N:]$KMQ$$$?%3%^%s%I$r<($9$3$H!#(B

$BLdBj(B-5

$BFbIt7k9g$H30It7k9g$N0c$$$r6qBNE*$J;vNc$rMQ$$$F@bL@$;$h!#(B

$BLdBj(B-6

$B:830It7k9g$H1&30It7k9g$N0c$$$r6qBNE*$J;vNc$rMQ$$$F@bL@$;$h!#(B

$BLdBj(B-7

fruit$B%F!<%V%k$r<+8J7k9g$7!"$=$N7k2L$rI=<($;$h!#(B $B$=$N:]$KMQ$$$?%3%^%s%I$r<($9$3$H!#(B

$BLdBj(B-8

$B30It7k9g$N2r@b$K$"$k!"(Bsyohin_tbl1$B$H(Bhanbai_tbl$B$N:81&$N=gHV$r5UE>$7!":8$r(Bhanbai_tbl, $B1&$r(Bsyohin_tbl1$B$K$;$h!#$=$7$F!"2r@b$K$"$k:830It7k9g$H1&30It7k9g$N$=$l$>$l$HF1$87k2L(B $B$r=P$9(BSQL$BJ8$r:n@.$7!"

$BLdBj(B-9

$B8r:97k9g$N2r@b$K$"$k!"(Bshinamono_tbl1$B$H(Bshinamono_tbl2$B$N8r:97k9g$,$J$<(B16$B9T$K$J$k$+$r@bL@(B $B$;$h!#(B

$B%7%9%F%`%W%m%0%i%_%s%01i=,(B


Yasuo NAGAI