平成30/ 2018-10-20 06:04
MYSQL/ INSERT

| 例1
|----------
insert into TwitterUser(user_id, user, user_name)
(
select distinct
    aa.from_user_id, aa.from_user, aa.from_user_name
from Twitters aa inner join
    (select max(id) as id, from_user_id from Twitters group by from_user_id) bb on
       aa.id = bb.id left outer join
    TwitterUser cc on
        aa.from_user_id   = cc.user_id   and
        aa.from_user      = cc.user      and
        aa.from_user_name = cc.user_name
where
    cc.user_id   is null and
    cc.user      is null and
    cc.user_name is null
);



| 例2
|----------
insert into TwitterUser(user_id, user, user_name) (
select a.from_user_id, a.from_user, a.from_user_name from Twitters a inner join
    (select max(id) as id, from_user_id from Twitters group by from_user_id) b on a.id = b.id
group by a.from_user_id
);



|
| Mysql Insert 重複
|----------
insert ignore into sampletbl(id, title) values(1, 'hohoho');
※ignoreを設定すると、重複エラーは無視される。
(参考)
http://variable.jp/?p=1251
http://webcache.googleusercontent.com/search?q=cache:kvfb5pQbgLoJ:dev.mysql.com/doc/refman/5.1/ja/insert.html+mysql+insert+ignore&cd=2&hl=ja&ct=clnk&gl=jp&client=firefox-a&source=www.google.co.jp