MySQL
 Computer >> コンピューター >  >> プログラミング >> MySQL

MySQLテーブルから1を選択するとはどういう意味ですか?


任意のテーブル名から「select1」というステートメントは、1のみを返すことを意味します。たとえば、いずれかのテーブルに4つのレコードがある場合、1を4回返します。

例を見てみましょう。まず、CREATEコマンドを使用してテーブルを作成します。

mysql> create table StudentTable
   -> (
   -> id int,
   -> name varchar(100)
   -> );
Query OK, 0 rows affected (0.51 sec)

レコードの挿入

mysql> insert into StudentTable values(1,'John'),(2,'Carol'),(3,'Smith'),(4,'Bob');
Query OK, 4 rows affected (0.21 sec)
Records: 4  Duplicates: 0  Warnings: 0

すべてのレコードを表示します。

mysql> select *from StudentTable;

これが出力です。

+------+-------+
| id   | name  |
+------+-------+
|    1 | John  |
|    2 | Carol |
|    3 | Smith |
|    4 | Bob   |
+------+-------+
4 rows in set (0.00 sec)

以下は、「select1」を実装するためのクエリです。

mysql> select 1 from StudentTable;

これが出力です。

+---+
| 1 |
+---+
| 1 |
| 1 |
| 1 |
| 1 |
+---+
4 rows in set (0.00 sec)

上記は4つのレコードに対して1を4回返し、5つのレコードがある場合、上記のクエリは1を5回返します。

Note: It returns 1 N times, if the table has N records.

  1. MySQLのストアドプロシージャからのテーブルレコードを表示する

    まずテーブルを作成しましょう- mysql> create table DemoTable1933    (    ClientName varchar(20)    ); Query OK, 0 rows affected (0.00 sec) 挿入コマンド-を使用して、テーブルにいくつかのレコードを挿入します mysql> insert into DemoTable1933 values('Chris Brown'); Query OK, 1 row affected (0.00 sec) mysql

  2. MySQLで値が存在しないテーブルから選択しますか?

    このために、NOT IN()-を使用できます mysql> create table DemoTable1991 (    StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    StudentName varchar(20) ); Query OK, 0 rows affected (0.61 sec) 挿入コマンド-を使用して、テーブルにいくつかのレコードを挿入します mysql> insert into DemoTable1991(StudentName) values('C