0% found this document useful (0 votes)
42 views3 pages

Maam Celine's SQL 101 Crash Course

This document provides an overview of SQL and JavaScript concepts like creating users, queries, joins, aggregations, editing rows, inserting rows, and deleting rows. It also covers database and table creation and deletion. Operators like IN, AND, and NOT are discussed as well as challenges involving coalesce, exists, and having.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views3 pages

Maam Celine's SQL 101 Crash Course

This document provides an overview of SQL and JavaScript concepts like creating users, queries, joins, aggregations, editing rows, inserting rows, and deleting rows. It also covers database and table creation and deletion. Operators like IN, AND, and NOT are discussed as well as challenges involving coalesce, exists, and having.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

=JAVASCRIPT and SQL CRASH COURSE=

– u is username (in mysql -u<user_name> -


p<password>)
– CREATE USER ‘christian’@‘localhost, GRANT
PRIVILEGES, FLUSH PR, SHOW PRI
– \G
– updaet_attrubute
– set table_name -> sql name of table

update statements and select

SELECT
– table = primary_key
– describe acccounts;
– tinyitnt(binary) 1
– primary key => id
– select * from accounts where id = <id>
– What if i dont know the id: select * from accounts where user_name
=“Ariana Grande”
– Only need specific columns,
– select id, name, email, company_name from accounts where id = 5;

JOIN (A ^ B)
– describe price_histories (belong to product);
– FOREIGN KEY -> user_id, account_id, product_id variat_id

– SIMPLIFIED QUERIES
– select products.name, price_histories.old_price, price_histories.new_price
– from prcie_historyes
– inner join products
– on price_histories.product_id = products.id
– where product.id = 2014234234;
– What if product has no price history?
– empty set
– LEFT JOINS
– select products.name, price_histories.old_price,
price_histories.new_price
– from prcie_historyes
– left join products
– on price_histories.product_id = products.id
– where product.id = 2014234234;
– RIGHT JOINS
– select products.name, price_histories.old_price,
price_histories.new_price
– from prcie_historyes
– right join products
– on price_histories.product_id = products.id
– where product.id = 2014234234;
– Find productsw

AGGREGATION (group by)


– select id, name from accounts where name = ‘ʼsimplithaiʼ
– select id , name from
– select count(id) from products where account_id = 22230;
– SAMPLE
– select account_id, p.id, name from products p limit 100;
– group by account_id

EDITING A ROW
– ex: select * from products where account_id =6154;
– how to add info to the
– update products set description = “Bakery Hot Item” where id = 2011465;
– i

INSERTING

– INSERT into products (stock_no, name, retail_price, cost, account_id)


VALUES (“”,52345gfdʼʼPB JUNKIE,ʼ75ʼ,50ʼʼ, 6154);

DESTROY
– delete from products where id = 2064321 (letʼs assume this is the pb);

AGGREGATION
What if products.count > 1000?
– select a.name, count(p.id) from accounts a inner join products p on
a.id=p.account_id
– group by a.name
– where count(p.id) > 1000; -> IS WRONG!
– HAVING (only to functions / methods) -> group by
– having count(p.id) > 1000

CREATING A DATABASE
– create database xtiantest default charset utf8;
– use xtiantest;
– show tables;
– create products (stock_no varchar(100), name varchar(100), cost
decimal(15,4) )

dESTROYING
– drop table Persons;
– drop database xtiantest;

OPERATORS

IN OPERATOR
– select name from products where account id= 5 liimt 10;

AND CONDITIONS
– select id ,name from products where account_id = 5 and retail_price < 2000;

NOT

CHALLENGE: HOMEWORK
– Coalesce and exict and having.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy