Solutions - SQL Basics

  1. Use

    select distinct residence from person;
    
  2. Use

    select count(distinct residence) from person;
    
  3. Use

    select * from person where name like '%oh%';
    
  4. Use

    select * from flight where date < "2014-10-20";
    
  5. Use

    select * from person where name in ('Philipp', 'Carlos') 
    

    and

    select * from person where name = 'Philipp' or name = 'Carlos'
    
  6. Use

    select * from person where name = 'Philipp' and age > 50;
    
  7. For all contracts use

    select count(*) from phone_contract;
    
  8. and for the actives ones

    select count(*) from phone_contract where status = 'active';
    
  9. We get all combinations of names and phone numbers.

  10. Use

    select person.name, person.age from person, phone_contract
    where person.name=phone_contract.name and status = 'active';
    
  11. Use

    select p.name, phone_number from person p, phone_contract c where
    p.name = c.name and age > 30;
    
  12. It returns name, age, residence and phone number for all people who have the same age as persons living in Paris.