SQL

Introduction

Structured Query Language. Keywords are case insensitive.
DBMS notes

mySQL using Docker

A basic working SQL server.

Pull docker image. Create a network. Start a server in a container. Create a client container and access the server.

Video



Commands


REGEX

AGGREGATION

GROUP BY

JOINS

UNION => DISTINCT
UNION ALL => DUPLICATES allowed


Curated Questions

1. Query even ID numbers in table STATION.

select * from station where MOD(id,2)=0;


2. Query to find the difference between the total number of cities and the unique number of cities in the table STATION.

select count(city)-count(distinct city) from station;


3. Query city with the longest name from table STATION

select city from station orderby length(city) desc, city limit 1;


4. Query the list of CITY names starting with vowels (i.e., a, e, i, o, or u) from STATION. Result cannot contain duplicates.

select distinct city FROM station WHERE city REGEXP "^[aeiou].*";