SQLite Select

https://www.sqlitetutorial.net/sqlite-select/

Summary: in this tutorial, you will learn how to use SQLite SELECT statement to query data from a single table.

The SELECT statement is 

one of the most commonly used statements in SQL. 

The SQLite SELECT statement 

provides all features of the SELECT statement in SQL standard.

概要:このチュートリアルでは、SQLiteのSELECT文を使って1つのテーブルからデータを照会する方法を学びます。
SELECT ステートメントは、SQL で最もよく使用されるステートメントの 1 つです。SQLite の SELECT 文は、標準 SQL の SELECT 文のすべての機能を備えています。

Simple uses of SELECT statement


You can use the SELECT statement

 to perform a simple calculation as follows:

SELECT ステートメントの簡単な使い方
SELECT ステートメントを使って、次のように簡単な計算を行うことができます。
SELECT	1 + 1;

画像4

You can use multiple expressions 

in the SELECT statement

 as follows:

SELECT文の中では、以下のように複数の式を使うことができます。
SELECT 
  10 / 5, 
  2 * 4 ;

画像5


Querying data from a table using the SELECT statement

SELECT ステートメントを使ったテーブルからのデータの問い合わせ

We often use the SELECT statement to query data from one or more table. The syntax of the SELECT statement is as follows:

1つまたは複数のテーブルからデータを照会するのに、SELECT文をよく使います。SELECT ステートメントの構文は以下の通りです。
SELECT DISTINCT column_list
FROM table_list
 JOIN table ON join_condition
WHERE row_filter
ORDER BY column
LIMIT count OFFSET offset
GROUP BY column
HAVING group_filter;

The SELECT statement is the most complex statement in SQLite. 

To help easier to understand each part, 

we will break the SELECT statement into multiple easy-to-understand tutorials.

SELECT ステートメントは、SQLite の中でも最も複雑なステートメントです。各部分を理解しやすくするために、SELECT文を複数のわかりやすいチュートリアルに分けて説明します。
SELECT column_list
FROM table;






Even though the SELECT clause appears before the FROM clause, SQLite evaluates the FROM clause first and then the SELECT clause, therefore:

SELECT句がFROM句の前にあっても、SQLiteはまずFROM句を評価し、次にSELECT句を評価します。

First, specify the table where you want to get data from in the FROM clause. Notice that you can have more than one table in the FROM clause. We will discuss it in the subsequent tutorial.
Second, specify a column or a list of comma-separated columns in the SELECT clause.
You use the semicolon (;) to terminate the statement.


まず、FROM句でデータを取得したいテーブルを指定します。FROM句には、複数のテーブルを指定できることに注意してください。これについては、この後のチュートリアルで説明します。
次に,SELECT句で列またはカンマで区切られた列のリストを指定します。
文章の最後にはセミコロン(;)を使います。

SQLite SELECT examples


Let’s take a look at the tracks table in the sample database.

trackid、トラック名、作曲者、単価などのデータをTracksテーブルから取得するには、次のステートメントを使用します。


画像1

The tracks table contains columns and rows. It looks like a spreadsheet.

トラックテーブルには、列と行があります。スプレッドシートのように見えます。

画像2

To get data from the tracks table such as trackid, track name, composer, and unit price, you use the following statement:

trackid、トラック名、作曲者、単価などのデータをTracksテーブルから取得するには、次のステートメントを使用します。


SELECT
	trackid,
	name,
	composer,
	unitprice
FROM
	tracks;

You specify 

a list column names, which you want to get data, in the SELECT clause 

and the tracks table in the FROM clause. 

SQLite returns the following result:

SELECT 句でデータを取得したい列名のリストを指定し、FROM 句でトラックテーブルを指定します。SQLiteは次のような結果を返します。


画像4


To get data from all columns, 

you specify the columns of the tracks table in the SELECT clause as follows:

すべての列からデータを取得するには、以下のようにSELECT句でTracksテーブルの列を指定します。​


SELECT * FROM tracks;







この記事が気に入ったらサポートをしてみませんか?