select statement-select row

Let's execute the select statement in MariaDB. The following select statement fetches all rows by specifying the "id", "name", "author_id" and "price" fields of the book table.

select id, name, author_id, price from book;

Specify all fields

Use "*" to specify all fields. It's easy to specify all the fields if performance isn't a burden.

select * from book;

Display fields vertically

You can display the field name vertically by specifying "\ G" instead of ";". This is useful when you have more fields.

select * from book \ G

Extract row by specifying ID

You can use the where clause to retrieve a row by specifying the id.

select * from book where id = 3;

Extract a row by specifying a price range

Let's use the where clause to retrieve a row by specifying a price range. Get a line where the price of a book is 1000 yen or more and less than 2000 yen.

select * from book where price> = 1000 and price <2000;

Let's take out cheap books of 500 yen or less and expensive books of 5000 yen or more.

select * from book where price <= 500 or price> = 5000;

Extract lines containing Perl in the book name

Let's use like to retrieve the line that contains Perl in the name of the book. "%" Represents 0 or more arbitrary characters.

select * from book where name like'%Perl%';

To include Perl at the beginning, write as follows.

select * from book where name like'Perl%';

Output to CSV file

The method of outputting the result of the select statement to the CSV file is explained below.

Associated Information