0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【MySQL】select * from テーブル名 と書かなくても全カラムを取得する方法

Posted at

はじめに

MySQLのリファレンスを読んでいたところ、select * from テーブル名と書かなくても、全部のカラムのデータを取得できる方法を見つけた。
この記事ではそのやり方を紹介する。

この記事の対象者

  • select * from テーブル名以外のやり方で全部のカラムのデータを取得する方法を知りたい人

検証環境

DBFiddleのMySQL8.0を使用する。

select version();
8.0.35

方法

MySQLのv8.0.19で導入された、tableステートメントを使う。
他のDBも少し調べてみたが、同じような機能はなく、MySQLの独自拡張と思われる。

table テーブル名

実際に試してみる

DDL

create table t1 (
  id int not null primary key,
  name varchar(20)
)
;
  
insert into t1 values
  (1, 'aaa'),
  (2, 'bbb')
;

DML

table t1;
id name
1 aaa
2 bbb

order byも書ける

table t1 order by id desc;
id name
2 bbb
1 aaa

limitも書ける

table t1 order by id desc limit 1;
id name
2 bbb

まとめ

  • tableステートメントを使えば、select * from テーブル名と書かなくても、全カラムのデータを取得可能

リファレンスを見ていると知らない機能がいっぱい出てきます。

参考資料

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?