SQL Queries
Some illustrative examples follow. Usually it will be obvious what the query is doing.
select a, b, c from table;
select * from table;
select distinct city from table;
select distinct city, country from table;
select first_name, last_name from students where marks > 80;
select first_name, last_name from students where marks != 42;
select first_name, last_name from students where marks between 80 and 90;
select city from table where amount > 5000 and tax < 50;
select score from table where name == "Shreyas" or name == "Sister";
select score from table where name in ("Shreyas", "Sister");
select score from table where name in (select first_name from family);
select customer_name, commodity, price from commodities order by price desc, customer, commodity asc;
select name from customers where phone_number is not null;
update customers set bonus_points = 0, redeemed_points = 0 where id = 25;
If you omit the
where
clause in anupdate
statement, ALL records will be updated!
delete from customers where first_name="Jeff";
If you omit the
where
clause in adelete
statement, ALL records will be deleted!
delete from customers;
select first_name, city from customers limit 50;`
The limit
syntax is MySQL-specific.
select employee_id, max(shipping_fee) from orders;
select min(price) from inventory;
select max(price) from inventory;
select avg(price) from inventory;
select sum(price) from inventory;