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

回答編集履歴

1

追記

2018/06/22 00:53

投稿

yambejp
yambejp

スコア117833

answer CHANGED
@@ -5,4 +5,12 @@
5
5
  select * from tableA as t1
6
6
  inner join tableB as t2 on t1.id=t2.id
7
7
  order by t1.id asc,t2.cd desc
8
+ ```
9
+ # 追記
10
+ もしcdの最大値だけとってid順に表示したということであればこう
11
+ ```SQL
12
+ select * from tableA as t1
13
+ inner join tableB as t2 on t1.id=t2.id
14
+ where not exists(select 1 from tableB where id=t2.id and cd>t2.cd)
15
+ order by t2.id asc
8
16
  ```