Results 1 to 4 of 4

Thread: SQL question

  1. #1
    Join Date
    Mar 2007
    Posts
    1

    SQL question

    Hey everybody,

    I am new to sql and have a problem to find the solution for this exercise: Find out the makers that sale PCs but not laptops.

    The database scheme consists of four relations:

    Product(maker, model, type)
    PC(code, model, speed, ram, hd, cd, price)
    Laptop(code, model, speed, ram, hd, screen, price)
    Printer(code, model, color, type, price)


    My own query:

    select distinct maker from product, pc
    where product.model = pc.model
    and type in('pc','printer')


    The problem is that i also get the makers who sells pc and laptops.

    Thnx for any help,

  2. #2
    Join Date
    Nov 2002
    Location
    New Jersey, USA
    Posts
    3,932
    This assumes that model is unique across makers and pc and laptop do not share a model name (may be true)

    select maker
    from product, pc
    where product.model = pc.model
    and model not in (select model from laptop)

  3. #3
    Join Date
    Sep 2007
    Posts
    1
    SELECT maker from product p,pc c where p.model=c.model
    AND type not in('laptop')

  4. #4
    Join Date
    Sep 2007
    Posts
    1
    the answer is:

    SELECT * FROM product WHERE not exists (select * from laptop where
    product.MODEL=laptop.model) and MAKER not in (SELECT MAKER FROM
    product WHERE model in (SELECT model FROM laptop)) and maker in
    (SELECT MAKER FROM product WHERE model in (SELECT MODEL FROM pc))

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •