You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
show databases;
createdatabasedb_name;
use db_name;
Make a Table in the Database
show tables;
createtabletable_name (
id int AUTO_INCREMENT,
name varchar(299),
age int
);
Inserting Data in the Table
show tables;
describe table_name;
insert into table_name values (1, "name", 25);
Pull Data from the Table
select*from table_name;
select name from table_name;
SELECT DISTINCT location FROM users;
SELECT*FROM users WHERE dept LIKE'd%';
SELECT*FROM users WHERE dept IN ('design', 'sales');
SELECT*FROM users WHERE age BETWEEN 20AND25;
select*from table_name where column_name = value;
select*from table_name where column_name = value or column_name = another_value;
select id from table_name where age <30;
select*from table_name where not column_name = value;
Remove Data from the Table
deletefrom table_name where column_name = value;
Update Data
update table_name set column_name = new_value where column_name = value;
Sorting
select*from table_name order by column_name asc;
select*from table_name order by column_name desc;
Generate Truly Random Ages for All Rows in One Command
UPDATE your_table_name
SET age = FLOOR(RAND() * (50-20+1)) +20WHERE id IN (1, 2, 3, 4, 5, 6, 7);