create table cars(
name text,
price integer,
speed integer,
carMrBinola text
); 



insert into cars(name, price, speed)
values('Bmw M5 F90 Competition 2018🚀🔥', 87000, 305); 

insert into cars(name, price, speed)
values('Bmw X5 M Competition 2024🚀🔥', 124000, 305);

insert into cars(name, price,speed)
values('Bmw E38 1980😊', 10000, 225);

insert into cars(name, price, speed, carMrBinola)
values('🔥', NULL, NULL, NULL);

insert into cars(name, price, speed, carMrBinola)
values('MrBinola HAS: Bmw X5 M Competition 2024', 124000, 305, '🤑Bmw X5 M Competition🤑');


select name, CONCAT(price, ' 🤑') as price, speed, carMrBinola
from cars;





-- delete from cars where price = 10000;

-- update cars
-- set price = 90000
-- where name = 'Bmw M5 F90 Competition 2018';

-- update cars
-- set speed = 310
-- where name = 'Bmw M5 F90 Competition 2018';

-- update cars
-- set price = 130000
-- where name = 'Bmw X5 M Competition 2024';

-- update cars
-- set speed = 290
-- where name = 'Bmw X5 M Competition 2024';

-- update cars
-- set speed = 210
-- where name = 'Bmw E38 1980';

-- update cars
-- set price = 9000
-- where name = 'Bmw E38 1980';



-- update cars
-- set name = 'Mercedes Benz'
-- where name = 'Bmw E38 1980😊';







-- select*from cars;











-- CREATE TABLE Person (
--   name character varying(10),
--   age integer unique,
--   hobby text Null,
--   job text not Null,
--   countCars integer check(countCars > 3),
--   countHome integer default 0
-- );


-- insert into Person(name,age,hobby, job, countCars, countHome)
-- values ('Roma',23,Null,'IT', 5,9);

-- insert into Person(name,age,hobby, job, countCars, countHome)
-- values ('Lev',13,'Sport','IT', 5,7);

-- select * from Person;





-- CREATE TABLE class(
-- name character varying(20),
-- number integer check(number < 11 and number > 0),
-- lastname text
-- );

-- insert into class(name,number,lastname)
-- values('MrBinola',9,'Shulha');
-- insert into class(name,number,lastname)
-- values('MrBeast',5,'GTR');
-- insert into class(name,number,lastname)
-- values('MirosAnt',7,'Retefull');


-- delete from class where name = 'MrBeast';
-- delete from class where name = 'MirosAnt';


-- select*from class;




-- CREATE TABLE Treck(
-- ID serial primary key, 
--   name text
-- );

-- -- insert into Treck(ID, name)
-- -- values(1, 'MirosAnt');
-- -- insert into Treck(ID, name)
-- -- values('7', 'MrBinola');

-- insert into Treck(name)
-- values('Roman'),
-- ('Vitalii'),
-- ('Dima'),
-- ('Lubomir');

-- select*from Treck;





-- create table person(
-- name text,
-- Age integer ,
-- hobby text
-- );
-- insert into person(name,Age,hobby)
-- values('Misha',9,'CaMpYtEr');
-- insert into person(name,Age,hobby)
-- values('Roman',21,'Programing');
-- insert into person(name,Age,hobby)
-- values('Maksim',13,'Programing');

-- insert into person(name,Age,hobby)
-- values('Misha',12,'CaMpYtEr');
-- insert into person(name,Age,hobby)
-- values('Roman',14,'Programing');
-- insert into person(name,Age,hobby)
-- values('Maksim',16,'Programing');



-- select*from person where name = 'Maksim' and Age = 16;
-- select*from person where name = 'Maksim';


-- select*from person where name = 'Misha' or name = 'Maksim';
-- select*from person where name in('Misha', 'Roman');


-- select*from person where Age < 18;


-- select*from person where Age > 18 and Age < 40;


-- select*from person where Age between 18 and 40;


-- select Distinct name from person;


-- select*from person limit 2;


-- select*from person order by Age;


-- select*from person order by Age desc;


-- select hobby from person;


-- select name, Age from person;


-- select*from person where name = 'Misha' and Age = 12;




-- create table person(
-- name text,
-- Age integer ,
-- hobby text
-- );
-- insert into person(name,Age,hobby)
-- values('Misha',9,'CaMpYtEr');
-- insert into person(name,Age,hobby)
-- values('Roman',21,'Programing');
-- insert into person(name,Age,hobby)
-- values('Maksim',19,'Programing');

-- insert into person(name,Age,hobby)
-- values('Misha',35,'CaMpYtEr');
-- insert into person(name,Age,hobby)
-- values('Roman',14,'Programing');
-- insert into person(name,Age,hobby)
-- values('Maksim',16,'Programing');


-- select max(Age) from person;

-- select min(Age) from person;

-- select sum(Age) from person;

-- select avg(Age) from person;

-- select string_agg(name, ',') from person;

-- select max(Age) as MaxElementAge from person;


-- I MrBinola! I YouTuber! I have 467 subscriber!
-- Oh there is a balcony in our room!




-- CREATE TABLE MrBinola(
-- name text unique,
-- price integer,
-- speed integer
-- );

-- insert into MrBinola(name, price, speed)
-- values('BMW X5 M', 100000, 240),
-- ('Audi Q7', 50000, 180),
-- ('Mercedes-Benz', 120000, 200),
-- ('Shkoda', 3000, 120),
-- ('Ferarri', 400000, 380),
-- ('LAMBORGHINI', 3000000, 430),
-- ('VOLVO', 200000, 100);

-- delete from MrBinola where name = 'Shkoda';
-- update MrBinola
-- set price = 1000
-- where name = 'BMW X5 M';

-- select*from MrBinola;
-- select max(price) from MrBinola;
-- select*from MrBinola where price between 1000 and 2000;
-- select*from MrBinola order by price desc;
-- select*from MrBinola limit 3;
-- select sum(price) from MrBinola;







-- CREATE TABLE Customers
-- (
--     Id SERIAL PRIMARY KEY,
--     FirstName VARCHAR(20) NOT NULL,
--     LastName VARCHAR(20) NOT NULL,
--     AccountSum NUMERIC DEFAULT 0
-- );
-- CREATE TABLE Employees
-- (
--     Id SERIAL PRIMARY KEY,
--     FirstName VARCHAR(20) NOT NULL,
--     LastName VARCHAR(20) NOT NULL
-- );
  
-- INSERT INTO Customers(FirstName, LastName, AccountSum) VALUES
-- ('Tom', 'Smith', 2000),
-- ('Sam', 'Brown', 3000),
-- ('Paul', 'Ins', 4200),
-- ('Victor', 'Baya', 2800),
-- ('Mark', 'Adams', 2500),
-- ('Tim', 'Cook', 2800);
  
-- INSERT INTO Employees(FirstName, LastName) VALUES
-- ('Homer', 'Simpson'),
-- ('Tom', 'Smith'),
-- ('Mark', 'Adams'),
-- ('Nick', 'Svensson');

-- select FirstName, LastName from Customers
-- except select FirstName, LastName from Employees;






-- CREATE TABLE PersonPro(
-- id SERIAL PRIMARY KEY,
-- name text,
-- countcars text[]
-- );

-- INSERT INTO PersonPro(name, countcars)
-- VALUES('Tima', '{"BMW X6M", "BMW M6"}'),
-- ('RomanProgramming', '{"BMW X5M", "BMW X6M", "BMW X6"}'),
-- ('RomanPro', '{"BMW X4M", "BMW X4M", "BMW X5"}');

-- select * from PersonPro;






-- CREATE TABLE Persones(
-- Id integer,
-- name text,
-- price integer
-- );

-- INSERT INTO Persones(Id, name, price)
-- VALUES(1, 'Vova', 16),
-- (2, 'Miron', 1000),
-- (1, 'Roman', 100),
-- (3, 'RomanPro', 100000),
-- (1, 'RomanPremium', 900000),
-- (2, 'RomanVip', 500000);

-- select Id, sum(price) from Persones group by Id;





-- CREATE TABLE Auto(
-- Id SERIAL PRIMARY KEY,
-- name text,
-- price bigint
-- );

-- INSERT INTO Auto(name, price)
-- VALUES('BMW X4', 30000),
-- ('BMW X5M', 40000),
-- ('BMW X6M', 250000),
-- ('BMW X7M', 300000),
-- ('BMW X3', 10000);

-- select * from Auto order by price;
-- select name from Auto
-- Where name = 'BMW X4';



-- CREATE TABLE SuperDID(
-- name text,
-- age integer
-- );

-- INSERT INTO SuperDID (name, age)
-- VALUES('Vova', 16),
-- ('Miron', 14),
-- ('Roman', 23),
-- ('RomanPro', 24 ),
-- ('RomanPremium', 25),
-- ('RomanVip', 27);

-- select max(age) from SuperDID;










-- CREATE TABLE JPS (
--     id SERIAL PRIMARY KEY,
--     "ім'я" VARCHAR(50),
--     вік INT
-- );



-- INSERT INTO JPS ("ім'я", вік) VALUES
-- ('Олександр', 25),
-- ('Mary', 30),
-- ('Ivan', 20),
-- ('Roman', 35),
-- ('Misha', 40);



-- SELECT AVG(вік) AS середній_вік FROM JPS;






-- CREATE TABLE Kileps_West (
--     id SERIAL PRIMARY KEY,
--     value INTEGER
-- );


-- CREATE TABLE Best_Solo (
--     id SERIAL PRIMARY KEY,
--     value INTEGER
-- );

-- INSERT INTO Kileps_West (value) VALUES (10), (20), (30), (40), (50);

-- INSERT INTO Best_Solo (value) VALUES (20), (30), (60), (70);

-- SELECT value
-- FROM Kileps_West
-- WHERE value NOT IN (SELECT value FROM Best_Solo)
-- UNION
-- SELECT value
-- FROM Best_Solo
-- WHERE value NOT IN (SELECT value FROM Kileps_West);






-- CREATE TABLE people (
--     id SERIAL PRIMARY KEY,
--     name VARCHAR(100),
--     age INT
-- );

-- INSERT INTO people (name, age)
-- VALUES 
--     ('MrBeast', 25),
--     ('PewDiePie', 34),
--     ('Markiplier', 31),
--     ('MrBinola', 15),
--     ('Jacksepticeye', 32),
--     ('Ninja', 29);



-- SELECT * FROM people WHERE id = 1;










-- CREATE TABLE company(
-- id SERIAL PRIMARY KEY,
-- name text
-- );

-- CREATE TABLE product(
-- id SERIAL PRIMARY KEY,
-- nameProduct text,
-- idCompany integer,
-- foreign KEY(idCompany) references company(id)
-- );

-- INSERT INTO company(name)
-- VALUES('Android'),
-- ('Apple');

-- INSERT INTO product(nameProduct, idCompany)
-- VALUES('ComputerApple', 2),
-- ('iPhone16ProMax', 2),
-- ('MicrophoneFIFINE', 1),
-- ('SONY', 1),
-- ('Apple', 2);

-- SELECT company.id, company.name, product.nameProduct FROM product
-- inner join company on company.id = product.idCompany;




-- CREATE TABLE Company(
-- id SERIAL PRIMARY KEY,
-- name text
-- );

-- CREATE TABLE Product(
-- id SERIAL PRIMARY KEY,
-- nameProduct text,
-- idCompany integer,
-- foreign KEY(idCompany) references Company(id)
-- );

-- INSERT INTO Company(name)
-- VALUES
-- ('Google'),
-- ('Apple'),
-- ('NVIDIA'),
-- ('NVIDIA');

-- INSERT INTO Product(nameProduct, idCompany)
-- VALUES
-- ('Mac', 2),
-- ('iPhone', 2),
-- ('Google Pixel', 1),
-- ('VisionPro', 2),
-- ('Google Pixel 8', 1),
-- ('Apple Watch', null),
-- ('Apple Watch', null);

-- SELECT Company.id, Company.name, Product.nameProduct FROM Product
-- -- inner join Company on Company.id = Product.idCompany;
-- -- right join Company on Company.id = Product.idCompany;
-- -- left join Company on Company.id = Product.idCompany;
-- -- cross join Company;
-- inner join Company on Company.id = Product.idCompany;






-- CREATE TABLE Account(
-- id SERIAL PRIMARY KEY,
-- name text
-- );

-- CREATE TABLE Phone(
-- id SERIAL PRIMARY KEY,
-- numberPhone text,
-- idAccount integer unique,
-- foreign KEY(idAccount) references Account(id)
-- );

-- INSERT INTO Account(name)
-- VALUES('Anna'),
-- ('Vitalii');

-- INSERT INTO Phone(numberPhone, idAccount)
-- VALUES('+7 8900406823', 2),
-- ('+7 8800406823', 1);


-- SELECT Account.id, Account.name, Phone.numberPhone FROM Phone
-- inner join Account on Account.id = Phone.idAccount;







-- CREATE TABLE Wait(
-- id SERIAL PRIMARY KEY,
-- name text
-- );

-- CREATE TABLE BigAuto(
-- id SERIAL PRIMARY KEY,
-- name text,
-- idWait integer,
-- foreign KEY(idWait) references Wait(id)
-- );


-- INSERT INTO Wait(name)
-- VALUES('Angelina'),
-- ('Misha');

-- INSERT INTO BigAuto(name, idWait)
-- VALUES('BMW M5 F90', 2),
-- ('BMW E38', 1),
-- ('BMW X5', 1);


-- SELECT Wait.id, Wait.name, BigAuto.name FROM BigAuto
-- inner join Wait on Wait.id = BigAuto.idWait;




-- CREATE TABLE numbers (
--     id SERIAL PRIMARY KEY,
--     value INT
-- );

-- INSERT INTO numbers (value) VALUES (5), (8), (10), (12), (15);

-- SELECT value
-- FROM numbers
-- WHERE value IN (8, 10);






-- CREATE TABLE Person (
--     id SERIAL PRIMARY KEY,
--     name VARCHAR(100) NOT NULL
-- );

-- CREATE TABLE LaptopPassword (
--     id SERIAL PRIMARY KEY,
--     password VARCHAR(50) NOT NULL,
--     person_id INTEGER UNIQUE REFERENCES Person(id) ON DELETE CASCADE
-- );


-- INSERT INTO Person (name) VALUES ('MrBinola');
-- INSERT INTO LaptopPassword (password, person_id) VALUES ('LockedWWW', 1);


-- SELECT 
--     Person.name, 
--     LaptopPassword.password
-- FROM 
--     Person
-- JOIN 
--     LaptopPassword 
-- ON 
--     Person.id = LaptopPassword.person_id;







 
by

PostgreSQL online editor

Write, Run & Share PostgreSQL queries online using OneCompiler's PostgreSQL online editor and compiler for free. It's one of the robust, feature-rich online editor and compiler for PostgreSQL. Getting started with the OneCompiler's PostgreSQL editor is really simple and pretty fast. The editor shows sample boilerplate code when you choose database as 'PostgreSQL' and start writing queries to learn and test online without worrying about tedious process of installation.

About PostgreSQL

PostgreSQL is a open source relational database system and is also knows as Postgres.

Key Features:

  • Postgres is not only free and open-source but also it is highly extensible.
  • Custom Data types and funtions from various programming languaues can be introduced and the good part is compiling entire database is not required.
  • ACID(Atomicity, Consistency, Isolation, Durability) compliant.
  • First DBMS which implemented Multi-version concurrency control (MVCC) feature.
  • It's the default database server for MacOS.
  • It supports all major operating systems like Linux, Windows, OpenBSD,FreeBSD etc.

Syntax help

1. CREATE

CREATE command is used to create a table, schema or an index.

Syntax:

         CREATE TABLE table_name (
                column1 datatype,
                column2 datatype,
                ....);

2. ALTER

ALTER command is used to add, modify or delete columns or constraints from the database table.

Syntax

ALTER TABLE Table_name ADD column_name datatype;

3. TRUNCATE:

TRUNCATE command is used to delete the data present in the table but this will not delete the table.

Syntax

TRUNCATE table table_name;

4. DROP

DROP command is used to delete the table along with its data.

Syntax

DROP TABLE table_name;

5. RENAME

RENAME command is used to rename the table name.

Syntax

ALTER TABLE table_name1 RENAME to new_table_name1; 

6. INSERT

INSERT Statement is used to insert new records into the database table.

Syntax

INSERT INTO table_name (column1, column2, column3, ...) VALUES (value1, value2, value3, ...);

7. SELECT

Select statement is used to select data from database tables.

Syntax:

SELECT column1, column2, ...
FROM table_name; 

8. UPDATE

UPDATE statement is used to modify the existing values of records present in the database table.

Syntax

UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition; 

9. DELETE

DELETE statement is used to delete the existing records present in the database table.

Syntax

DELETE FROM table_name where condition;