SQL Queries on Sailors and Boat Schema | 100+ Queries

SQL Queries on Sailors and Boat Schema. In this seaworthy article, we’ll delve into the depths of databases and set sail on a quest to uncover insights about sailors and the vessels they command. We’ll start with a brief overview of our schema, then navigate through a treasure trove of SQL queries, complete with answers and explanations. So hoist the anchor and let’s embark on this SQL adventure!

Schema Overview: Our maritime database comprises two primary tables: Sailors and Boats. The Sailors the table holds information about intrepid sailors, while the Boats table contains details about the vessels that brave the open sea. Here’s a glimpse of our schema:

SQL Queries on Sailors and Boat Schema Definition

Sailors Table:

sid (Sailor ID, Primary Key)
sname (Sailor Name)
rating (Rating of the Sailor)
age (Age of the Sailor)

Boat Table:

bid (Boat ID, Primary Key)
bname (Boat Name)
color (Color of the Boat)
length (Length of the Boat)

SQL Queries Sailors and Boat Schema:

Table of Contents | SQL Queries List:

1. Retrieve all sailor names:

SELECT sname FROM Sailors;

2. List the names of sailors aged 25 or younger:

SELECT sname FROM Sailors WHERE age <= 25;

3. Find sailors with a rating above 8:

SELECT sname FROM Sailors WHERE rating > 8;

4. Display boat names and their colors:

SELECT bname, color FROM Boats;

5. List sailors and their ratings in ascending order of age:

SELECT sname, rating FROM Sailors ORDER BY age ASC;

6. Count the number of sailors:

SELECT COUNT(*) FROM Sailors;

7. Find the length of the longest boat:

SELECT MAX(length) FROM Boats;

8. Retrieve the average age of sailors:

SELECT AVG(age) FROM Sailors;

9. Find boats that are not green:

SELECT bname FROM Boats WHERE color <> 'green';

10. List sailors who are either 18 years old or have a rating of 10:

SELECT sname FROM Sailors WHERE age = 18 OR rating = 10;

Leave a Comment