SQL SELECT Statement: Basic Guide for Beginners




 Introduction

When you begin working with databases like Oracle, one of the first SQL commands you’ll learn is SELECT. It's used to fetch data. Understanding how to use SELECT properly will help you write better queries and retrieve exactly what you need.


Step 1: The Basic SELECT Syntax


SELECT column1, column2  

FROM table_name;


➡️ This retrieves the values of column1 and column2 from table_name.


Step 2: Selecting All Columns


SELECT *  

FROM table_name;


➡️ The asterisk * means all columns from the table. Use it when you need everything, but with caution, as it might return more data than needed.


Step 3: Filtering Data Using WHERE


SELECT column1, column2  

FROM table_name  

WHERE column1 = 'some_value';


➡️ Only rows where column1 has some_value will be returned.


Step 4: Combining Conditions


SELECT *  

FROM table_name  

WHERE column1 = 'value1' AND column2 = 'value2';


➡️ Use AND, OR to combine conditions and refine the result set.


Step 5: Limiting Results / Sorting


Sorting:


SELECT *  

FROM table_name  

ORDER BY column1 ASC;


➡️ ASC for ascending, use DESC for descending.


Limiting: (depends on your database version, Oracle uses ROWNUM or newer syntax):


SELECT *  

FROM table_name  

WHERE ROWNUM <= 10;


Conclusion

The SELECT statement is fundamental to SQL. Once you master it — using filters, sorting, limiting — you’ll be able to extract meaningful data from your tables. In the next guide, we’ll dive into how to use JOIN to combine data from multiple tables.

Comments