これは、最新の日付のID値を取得するための最良の方法ですか?
table1
id,entrydate
1,8/23/2012
2,8/24/2012
3,8/23/2012
select id from table1 where entrydate = ( select MAX(entrydate) from table1 )
これは、最新の日付のID値を取得するための最良の方法ですか?
table1
id,entrydate
1,8/23/2012
2,8/24/2012
3,8/23/2012
select id from table1 where entrydate = ( select MAX(entrydate) from table1 )
あなたはすでにそこに良い道を持っています. 私はネクタイに気をつけます:
select top id from table1 where entrydate = ( select MAX(entrydate) from table1 )
もちろん、これは SQL Server を使用していることを前提としています。
SQL-Server を使用していると仮定すると、次ORDER BY
の行を使用して取得できます。
SELECT TOP 1 id
FROM table
ORDER BY entrydate DESC
MySql では次のようになりますLIMIT
。
SELECT id
FROM table
ORDER BY entrydate DESC
LIMIT 1
オラクルの場合:
SELECT id
FROM (SELECT id FROM table ORDER BY entrydate DESC)
WHERE ROWNUM = 1
正確ではありませんが、これを行いたい:
SQL サーバーの場合:
SELECT TOP 1 id, MAX(entrydate) FROM table1 GROUP BY id
MySQL の場合:
SELECT id, MAX(entrydate) FROM table1 GROUP BY id LIMIT 1
SELECT id FROM table1 ORDER BY entrydate DESC LIMIT 1
あなたはできるはずですSELECT id FROM table1 ORDER BY entrydate DESC LIMIT 1