filmov
tv
How to select Distinct values in MySQL, For SQL Developers

Показать описание
Take a top-rated and up-to-date MySQL course on our Channel to learn valuable and practical skills. Whether you want the fundamentals, a deep-dive or specialized topics, our Channel got a course on deck. Learn with hands-on projects and gain a competitive edge in your field.
To take full advantage of this free training, we recommend watching all the videos in the playlist in the order.
Example & Sample data:
-- Distinct --
select distinct ID from
(
select 1 ID
union all
select 2
union all
select 1
union all
select 3
union all
select 3
) query1;
create table Cust (CustID int primary key, city_name varchar(50));
insert into Cust (custid, city_name) values (1,'city1');
insert into Cust (custid, city_name) values (2,'city2');
insert into Cust (custid, city_name) values (3,'city3');
insert into Cust (custid, city_name) values (4,'city4');
insert into Cust (custid, city_name) values (5,'city3');
insert into Cust (custid, city_name) values (6,'city3');
insert into Cust (custid, city_name) values (7,'city3');
insert into Cust (custid, city_name) values (8,'city2');
insert into Cust (custid, city_name) values (9,'city2');
insert into Cust (custid, city_name) values (10,'city2');
insert into Cust (custid, city_name) values (11,'city4');
insert into Cust (custid, city_name) values (12,'city4');
insert into Cust (custid, city_name) values (13,'city4');
insert into Cust (custid, city_name) values (14,'city5');
insert into Cust (custid, city_name) values (15,'city6');
insert into Cust (custid, city_name) values (16,'city1');
select city_name from Cust c
select DISTINCT city_name from Cust c
To take full advantage of this free training, we recommend watching all the videos in the playlist in the order.
Example & Sample data:
-- Distinct --
select distinct ID from
(
select 1 ID
union all
select 2
union all
select 1
union all
select 3
union all
select 3
) query1;
create table Cust (CustID int primary key, city_name varchar(50));
insert into Cust (custid, city_name) values (1,'city1');
insert into Cust (custid, city_name) values (2,'city2');
insert into Cust (custid, city_name) values (3,'city3');
insert into Cust (custid, city_name) values (4,'city4');
insert into Cust (custid, city_name) values (5,'city3');
insert into Cust (custid, city_name) values (6,'city3');
insert into Cust (custid, city_name) values (7,'city3');
insert into Cust (custid, city_name) values (8,'city2');
insert into Cust (custid, city_name) values (9,'city2');
insert into Cust (custid, city_name) values (10,'city2');
insert into Cust (custid, city_name) values (11,'city4');
insert into Cust (custid, city_name) values (12,'city4');
insert into Cust (custid, city_name) values (13,'city4');
insert into Cust (custid, city_name) values (14,'city5');
insert into Cust (custid, city_name) values (15,'city6');
insert into Cust (custid, city_name) values (16,'city1');
select city_name from Cust c
select DISTINCT city_name from Cust c