Categories
mySQL

mySQL Lesson 2

select *
from orders
order by id
limit 100;

select *
from order_items
order by id
limit 100;

Categories
mySQL

mySQL lesson 1

select a table in the db and show info from this table:

SELECT * FROM celebs;

create DB table:

CREATE TABLE celebs (id INTEGER, name TEXT, age INTEGER);

insert info into DB:

INSERT INTO celebs (id, name, age) VALUES (1, 'Justin Bieber', 21);

INSERT INTO celebs (id, name, age) VALUES (2, 'Beyonce Knowles', 33);

INSERT INTO celebs (id, name, age) VALUES (3, 'Jeremy Lin', 26);

INSERT INTO celebs (id, name, age) VALUES (4, 'Taylor Swift', 26);

update a row in the DB

UPDATE celebs
SET age = 22
WHERE id = 1;

SELECT * FROM celebs;

Add a new column to the table

ALTER TABLE celebs ADD COLUMN twitter_handle TEXT;

SELECT * FROM celebs;

add information to this new column

UPDATE celebs
SET twitter_handle = '@taylorswift13'
WHERE id = 4;

SELECT * FROM celebs;

delete rows that have a NULL value

UPDATE celebs
SET twitter_handle = '@taylorswift13'
WHERE id = 4;
DELETE FROM celebs WHERE twitter_handle IS NULL;

SELECT * FROM celebs;