Updated On: Tutorial updated and rechecked on 25th of September 2022
Views: 3,001
In the last tutorial we created a new database in MariaDB, we also created a new table with some fields and inserted some data.
The data included information about English football teams, their nicknames, stadium_name and capacity.
In this tutorial we will use basic MySQL queries to output information from the database.
Display all records from the table. Display records by id number, in ascending order
SELECT * FROM teams ORDER BY id ASC;
Display all records from the table. Display records by id number, in descending order
SELECT * FROM teams ORDER BY id DESC;
Display all records from the table. Display records by name
SELECT * FROM teams ORDER BY team;
Display all records but only the team field. Display records by id number, in ascending order
SELECT team FROM teams ORDER BY id ASC;
Display all records but only the team and nickname fields. Display records by id number, in ascending order
SELECT team, nickname FROM teams ORDER BY id ASC ;
Count the total number of records in teams table
SELECT COUNT(id) FROM teams;
Display all records where the field capacity is more than 30000 but less than 35000
SELECT * FROM teams WHERE capacity > 30000 AND capacity < 35000;
Display records from the team field beginning with the letter b
SELECT * FROM teams WHERE teams LIKE 'b%';
Display records from the team field beginning with the b and a
SELECT * FROM teams WHERE team LIKE 'b%' OR team LIKE 'a%';