Posts

Showing posts with the label sql

Understand the query command that uses two tables in MySQL(or Postgresql)

Image
mysql join create table student(id integer, name varchar(100)); insert into student(id, name) values(0, "yingshaoxo"); insert into student(id, name) values(1, "god"); create table takes(id integer, course varchar(100)); insert into takes(id, course) values(0, "english"); insert into takes(id, course) values(0, "coding"); insert into takes(id, course) values(0, "business"); insert into takes(id, course) values(1, "english"); insert into takes(id, course) values(2, "web_design"); select * from student; select * from takes; select student.id, student.name, takes.course from (student join takes on student.id = takes.id); Other join keywords that may not useful SELECT whatever FROM TableA a INNER JOIN TableB b ON a.column_name_1 = b.column_name_1 WHERE b.ok = 'yes' SELECT order_table.id AS Id, user_table.banned AS User_got_banned, order_table.request_at AS Day , order_table. status AS Order_st...

Play with PostgreSQL

Made by yingshaoxo  CREATE TABLE people ( name varchar ( 80 ), age int , -- how long you live createDate date ); INSERT INTO people VALUES ( 'hero hu' , 18 , '2021-09-1' ); INSERT INTO people VALUES ( 'kristine' , 25 , '2021-09-1' ); SELECT * FROM people; SELECT name FROM people; SELECT * FROM people WHERE age = 25 ; CREATE TABLE sex ( name varchar ( 80 ), sex varchar ( 80 ) ); INSERT INTO sex VALUES ( 'hero hu' , 'male' ); INSERT INTO sex VALUES ( 'kristine' , 'female' ); SELECT people.name, age, sex.sex, people.createdate FROM people JOIN sex ON people.name = sex.name; SELECT people.name, age, sex.sex, people.createdate as date FROM people JOIN sex ON people.name = sex.name; SELECT max (age) FROM people; SELECT min (age) FROM people; SELECT * FROM people WHERE name LIKE ...