This command is used to select only non-duplicate values. In MySQL, the DISTINCT keyword is used to retrieve unique values from a specified column in a table. It eliminates duplicate rows and returns only distinct rows. The basic syntax for using DISTINCT in a SELECT query is as follows:


SELECT DISTINCT column_name1, column_name2, … FROM table_name;

Let’s consider below table…

Let’s see usage of DISTINCT for column’s

Here’s a breakdown of how DISTINCT works:

  • The SELECT statement specifies the columns you want to retrieve unique values from. You can select one or multiple columns separated by commas.
  • The DISTINCT keyword is placed immediately after the SELECT keyword. It tells the MySQL server to return only distinct rows.
  • The FROM clause indicates the table from which you want to fetch the unique values.

Let’s consider another table:

Lets’ see another implementation:


In MySQL, a VIEW is a virtual table that represents the result of a pre-defined query. It allows you to encapsulate complex or frequently used SQL queries into a named object, making it easier to retrieve data without rewriting the query every time.

Creating a VIEW involves defining the query that defines the view’s data, and then you can use the view in subsequent queries as if it were a regular table.

The basic syntax to create a VIEW in MySQL is as follows:

CREATE  VIEW  view_name  AS  SELECT  column1, column2, …  FROM  table_name  WHERE  condition;

In a college, the Computer Science H.O.D can grant access to the college database for students to learn about the DBMS system. To prevent accidental data loss, the H.O.D can create a read-only view of the database on a local machine accessible to all students. This ensures understanding without the risk of crucial tables being dropped or deleted, safeguarding the college’s data integrity.

In simple words, VIEW basically a virtual table. A view in database, can be created for multiple reasons.

Now lets see how we can create a view


CREATE VIEW view_name AS SELECT * FROM table_name;

Let’s see actual implementation of VIEW in MySQL:

Lets’ make a VIEW for employees table in MySQL:

For delete a VIEW from database, you need use syntax:

DROP VIEW view_name;