現在、テーブルに次のようなデータがあります。
id | type
------------
1 | 1
2 | 1
3 | 2
4 | 2
5 | 3
6 | 3
6 | 3
次のようなデータを表示する必要があります。
Type 1
--All type ones go here
Type 2
-- All type twos go here
Type 3
All type threes go here
私が現在行っている方法は、2 つの別個の SQL ステートメントとループを使用することです。
select distinct type as type from table
while()
{
select type from table where type = type;
while()
{
}
}
これを実行して必要な結果を得るためのより良い方法はありますか、それとも 2 つのループを使用する唯一の方法ですか?