Results: 1578
Notes
  • Newest first
  • Oldest first
  • Newest first(All)
  • Oldest first(All)
IN
Selects all students that has one of the following last names
გოგია
გაგუა
გოგუა
SELECT *
FROM students
WHERE last_name IN ('გოგია', 'გაგუა', 'გოგუა')
Filtering the result using
IN
with sub-query:
SELECT
    *
FROM
    students
WHERE
    last_name IN(
        SELECT
            last_name
        FROM
            students
        WHERE
            id <= 5
    )
Alternative of the query using
=
operator:
SELECT *
FROM students
WHERE last_name = 'გოგია' 
OR last_name = 'გაგუა'
OR last_name = 'გოგუა'
by Valeri Tandilashvili
4 years ago
0
MySQL
IN
1
Set column at the top
Makes the column first - sets it at the top
ALTER TABLE note
CHANGE COLUMN title title VARCHAR(210) FIRST
The same thing using
MODIFY
ALTER TABLE note
MODIFY COLUMN title VARCHAR(210) FIRST
by Valeri Tandilashvili
4 years ago
0
MySQL
ALTER TABLE
1
ALTER TABLE note
CHANGE COLUMN title title VARCHAR(210) AFTER author_id
Another way to do the same thing is to use
MODIFY
instead of
CHANGE
ALTER TABLE note
MODIFY COLUMN title VARCHAR(210) AFTER description
by Valeri Tandilashvili
4 years ago
0
MySQL
ALTER TABLE
Full MySQL Course for Beginners
1
Deletes column
title
from table
note
ALTER TABLE note 
DROP COLUMN title;
COLUMN
is optional. The following query is alternative to the first one:
ALTER TABLE note 
DROP title;
by Valeri Tandilashvili
4 years ago
0
MySQL
ALTER TABLE
Full MySQL Course for Beginners
1
Renames the column
name
to
title
ALTER TABLE note CHANGE name title VARCHAR(210)
by Valeri Tandilashvili
4 years ago
0
MySQL
ALTER TABLE
Full MySQL Course for Beginners
1
Changes the column type to
VARCHAR(200)
ALTER TABLE note
MODIFY COLUMN title VARCHAR(200) NOT NULL;
by Valeri Tandilashvili
4 years ago
0
MySQL
ALTER TABLE
Full MySQL Course for Beginners
1
Adds column
author_id
to the table
note
after
title
column
ALTER TABLE note
ADD COLUMN author_id int not null default 0 AFTER title;
by Valeri Tandilashvili
4 years ago
0
MySQL
ALTER TABLE
Full MySQL Course for Beginners
1
Changes
AUTO_INCREMENT
value for
note
table to
100000
ALTER TABLE note
AUTO_INCREMENT = 100000;
by Valeri Tandilashvili
4 years ago
0
MySQL
ALTER TABLE
AUTO_INCREMENT
Full MySQL Course for Beginners
1
Adding AUTO_INCREMENT to any varchar column
Adding
AUTO_INCREMENT
to any
varchar
column first requires the column to be converted into
int
CREATE TABLE note (
    title varchar(50),
    description varchar(50),
    PRIMARY KEY(title)
);
INSERT INTO `note` (`title`, `description`) VALUES ('first', 'value'), ('second', 'value');
Let's add
AUTO_INCREMENT
to
title
column. We are not able to add
AUTO_INCREMENT
without changing it's type to
int
ALTER TABLE note MODIFY title int NOT NULL AUTO_INCREMENT;
Note: In such cases If the table contains rows with string values, (for
AUTO INCREMENT
field) the string values will be replaced with numbers starting with 1
by Valeri Tandilashvili
4 years ago
0
MySQL
AUTO_INCREMENT
1
Add AUTO_INCREMENT to an existing column
Let's first create
note
table without any column to have
AUTO_INCREMENT
CREATE TABLE note (
    id int,
    title varchar(50),
    description varchar(50),
    PRIMARY KEY(id, title)
);
After running the query above, we can add
AUTO_INCREMENT
feature to the existing column
id
ALTER TABLE note MODIFY id int NOT NULL AUTO_INCREMENT;
If the column is not
primary key
initially, we can modify the query, not to cause any error when adding
AUTO_INCREMENT
to it
CREATE TABLE note (
    id int,
    title varchar(50),
    description varchar(50)
);
Adding
AUTO_INCREMENT
feature to the column, that is not selected as a
primary key
ALTER TABLE note MODIFY id int NOT NULL PRIMARY KEY AUTO_INCREMENT
by Valeri Tandilashvili
4 years ago
0
MySQL
AUTO_INCREMENT
1
Results: 1578