SQL DISTINCT
SELECT DISTINCT column1, column1, ..... FROM TABLE
/*DISTINCT WILL NOT SELECT THE SAME VALUES IN SAME COLUMN*/
sql insert pentru fiecare valoare distinctă
insert into your_table (col1, col2, col3)
select distinct col1, 'newval', col3
from your_table
insert sql pentru fiecare valoare distinctă
insert into your_table (col1, col2, col3)
select distinct col1, 'newval', col3
from your_table
sql unic
This constraint ensures all values in a column are unique.
Example 1 (MySQL): Adds a unique constraint to the id column when
creating a new users table.
CREATE TABLE IF NOT EXISTS users (
id int NOT NULL,
name varchar(255) NOT NULL,
UNIQUE (id)
);
Example 2 (MySQL): Alters an existing column to add a UNIQUE
constraint.
ALTER TABLE users
ADD UNIQUE (id);
sql unic
This constraint ensures all values in a column are unique.
Example 1 (MySQL): Adds a unique constraint to the id column when
creating a new users table.
CREATE TABLE IF NOT EXISTS users (
id int NOT NULL,
name varchar(255) NOT NULL,
UNIQUE (id)
);
Example 2 (MySQL): Alters an existing column to add a UNIQUE
constraint.
ALTER TABLE users
ADD UNIQUE (id);
cum se selectează elementul unic în sql
DISTINCT
- select distinct * from employees; ==>
retrieves any row if it has at
least a single unique column.
- select distinct first_name from employees; ==>
retrieves unique names
from table. (removes duplicates)
- select distinct count(*) from employees;
retrieve number of unique rows
if any row has at least a single unique data.
element unic în sql
DISTINCT
- select distinct * from employees; ==> retrieves any row if it has at
least a single unique column.
- select distinct first_name from employees; ==> retrieves unique names
from table. (removes duplicates)
- select distinct count(*) from employees; retrieve number of unique rows
if any row has at least a single unique data.
sql unic selectați
SELECT DISTINCT col1, col2, ....
FROM table_name;
SELECT col1, MIN(col2)
FROM table_name
GROUP BY col1;