DEV Community

Mohammed Azim J
Mohammed Azim J

Posted on

SELECT Query

I was learning SQL SELECT queries using the dvdrental database, and I realized that SELECT is probably the most used SQL command because every time we want to see data from a database, we use SELECT.

The most basic query I tried was to just see customer names from the customer table.

SELECT first_name FROM customer;

I used this to just view the first names and check if the table had data.

Then I wanted more details about customers, so instead of only first name, I selected multiple columns.

SELECT first_name, last_name, email FROM customer;

I used this because usually when viewing customers, name and email are more useful together rather than just first name alone.

After that, I wanted to see the entire table to understand all the columns available.

SELECT * FROM customer;

I used this only to explore the table and understand the structure, not for regular use.

Then I tried filtering data to see only customers from a specific store.

SELECT first_name, last_name FROM customer
WHERE store_id = 1;

I used this to filter customers belonging to one store only.

Next, I tried finding customers with a specific last name.

SELECT first_name, last_name FROM customer
WHERE last_name = 'Smith';

I used this to search for a particular customer by last name.

Then I wanted to sort customers alphabetically.

SELECT first_name, last_name FROM customer
ORDER BY first_name;

I used this to display names in alphabetical order so it is easier to read.

Finally, I tried limiting the number of results.

SELECT first_name, last_name FROM customer
LIMIT 5;

I used this to only see a few rows instead of the entire table.

Top comments (0)