Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

MYSQL POSTGRE QUERIES

Postgre:

create table tyu(n int);


insert into tyu values(1.2),(1.3), (1.4), (1.5) returning *;
select * from tyu order by n desc ;
create table dummy_table(name varchar(20),address text,age int);

ALTER TABLE tyu


ALTER COLUMN n TYPE float;

select * from dummy_table order by name desc ;


insert into dummy_table values('XYZ1','location-A',25);
insert into dummy_table values('ABC1','location-B',35);
insert into dummy_table values('DEF1','location-C',40);
insert into dummy_table values('PQR1','location-D',54);
commit;
select * from dummy_table;
update dummy_table set age=50 where name='PQR';
update dummy_table set name='GHI',age=54 where address='location-D';

update dummy_table set age=30 where name='XYZ' returning age as age_no;


delete from dummy_table where age=35;
select * from dummy_table where age >=50;

select * from dummy_table where age<>50;

select distinct age from dummy_table order by 1;

create table dummy_table2 as select * from dummy_table;


select * from dummy_table2;

drop table if exists dummy_table2;

select * from vi2 ;

select * from dummy_table2 order by name desc LIMIT 2

show table dummy_table2


create or replace view vi2 as select * from dummy_table
where age is NOT NULL;

select 'My name is X' as col1 , 10 as col2, 'Address is -XYZ location' as col3
into new_table;

select * from new_table;

select * from information_schema.columns where table_name = 'tyu'

Select column_name from public.columns


where table_name = dummy_table2;

Select * from information_schema."tables" where table_name = 'new_table';


------------------------------

mysql

select * from sakila.actor;

desc sakila.actor;

select * from sakila.actor order by actor_id desc;

insert into sakila.actor values( 202, 'RAM', 'TRIPATHI', sysdate());

select (round(avg(sql_quotient),2)) as answer


from
Students GROUP BY substr(group_id,1,1) order by avg(sql_quotient)
desc limit 1;

select * from sakila.actor where first_name like 'ADA%' order by


first_name;

select actor_id, first_name, last_name


from
(select *, row_number( ) over (partition by first_name
order by actor_id) as rn
from sakila.actor
order by actor_id) x
where x.rn > 1 and first_name like 'ADA%' limit 10;
select * from world.city

CREATE TRIGGER upd_check AFTER INSERT ON world.city FOR EACH ROW IF NEW.population
< 0 THEN SET NEW.population = 0; END IF;

SELECT * FROM world.city WHERE population > 100 LIMIT 2

SELECT ROUND(45e-1)

You might also like