There are several clauses available in sequel for sorting and filtering data. In the last article, we discussed about the ORDER BY clause which is one of the most useful clauses in SQL when it comes to sorting and filtering data. In addition to the ORDER BY clause, we also have the WHERE clause and the SELECT DISTINCT clause. In this article, we shall discuss in details the meaning of these two clauses and their respective syntax.
The WHERE clause is used to specify conditions for filtering records in a query. In other words, it filters records in SQL query based on a specified condition. Its a clause you use most times with the SELECT SQL COMMAND and the UPDATE SQL COMMAND. The ultimate goal of the WHERE clause is to extract only the records that meet your criteria or condition, allowing for a more precise data retrieval. It’s syntax is written the following way:
SELECT column1_name, column2_name FROM table_name WHERE condition = ?;
For example, you can use the following syntax to retrieve from a table the name of employees whos ages are more than 30.
SELECT * FROM employees WHERE age > 30;
The SELECT DISTINCT clause is a clause in the Structured Query Language used to remove duplicate rows from the result set of a query. It ensures that the query returns only unique values for the specified columns. Simply put, if you want to get the list of unique items in a table, you use the SELECT DISTINCT clause. Its syntax should be written as:
SELECT DISTINCT column1, column2
FROM table_name;
Every database needs to be sorted accordingly and filtered whether its the arrangement of the database or how to select certain subjects from the database, sorting and filtering is an essential part to really relating well with your database. In this article, we covered the various clause in MySQL that can be used to sort and filter your data in a database.
Introduction Python is a programming language that has a large sum of frameworks. One of…
Introduction What is Cloud Computing? According to Wikipedia, Cloud Computing is a paradigm for enabling…
Introduction In the fast paced world of technology, learning a versatile and high-in-demand programming language…
Introduction User Authentication policy is a very crucial process for every application and organization. It…
Introduction In previous articles, we have learnt about Django, how it works and how we…
Introduction In this article, we shall learn how to build and implement a blog app.…