teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

chousei

2020/06/09 12:32

投稿

yambejp
yambejp

スコア117942

answer CHANGED
@@ -7,18 +7,18 @@
7
7
  (3,'c'),
8
8
  (4,'d');
9
9
 
10
- create table articles_users(id int,user_id varchar(10),article_id int);
10
+ create table articles_users(id int,user_id int,article_id int);
11
11
  insert into articles_users values
12
+ (1,1,1),
12
- (1,'a',1),
13
+ (1,2,1),
13
- (1,'b',1),
14
- (1,'c',2),
14
+ (1,3,2),
15
- (1,'d',2);
15
+ (1,4,2);
16
16
 
17
17
  select * from users as t1
18
18
  where exists(
19
19
  select 1
20
20
  from articles_users
21
- where t1.name=user_id
21
+ where t1.id=user_id
22
22
  group by user_id
23
23
  having sum(article_id=1)=0
24
24
  );