Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2007
    Posts
    3

    Unanswered: nested sql query

    select a.clientname, c.catlabel
    from clientsegueads a product_adcategories b product_categories c
    WHERE b.catid
    IN (select c.catid from product_categories where c.cadid = "493")
    LIMIT 3;

    clientsegueads
    ----------------------
    cadid
    clientname

    product_adcategories (bridge table)
    --------------------------------
    cadid
    cat_id

    product_categories
    ----------------------------
    cat_id
    cat_label

    any clues what im donig wrong ?

  2. #2
    Join Date
    Sep 2007
    Posts
    3
    im trying to select 3 random products from clientsegueads from the same category such as Health.

  3. #3
    Join Date
    Sep 2007
    Posts
    3
    I tried this .. doesnt work .. not sure ???

    SELECT a.clientname
    FROM clientsegueads a LEFT JOIN product_adcategories b ON a.cadid = b.cadid
    LEFT JOIN product_categories c ON ( b.catid = c.catid
    AND b.cadid = "342" )
    WHERE a.disabled = 'N'
    AND stopdate > NOW( )
    AND b.cadid <> "342"
    ORDER BY RAND( )
    LIMIT 3

  4. #4
    Join Date
    Mar 2007
    Location
    636f6d7075746572
    Posts
    770
    Can you provide some DDL + data so that I may provide a quick solution for you?

  5. #5
    Join Date
    Mar 2007
    Location
    636f6d7075746572
    Posts
    770
    First guess :

    Code:
    SELECT c.clientname
    FROM product_categories pc
    JOIN product_adcategories pa ON pc.cat_id = pa.cat_id
    JOIN clientsegueads c ON c.cadid = pa.cadid
    WHERE pc.cat_label = 'health'
    ORDER BY RAND()
    LIMIT 0,3

Posting Permissions

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