#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2004
    Posts
    32
    Rep Power
    11

    Help on multiple conditon select


    Hi,

    With the partial table


    ID Date Host Segment
    23729 2010-02-22 Bob News
    23730 2010-02-22 Bill Sports
    23731 2010-02-22 Sam Weather
    23732 2010-02-22 Bill Rap Up
    23733 2010-02-22 Sam Rap Up
    23734 2010-02-23 Bob News
    23735 2010-02-23 Sam Sports
    23736 2010-02-23 Bill Weather
    23737 2010-02-23 Bill Rap Up
    23738 2010-02-23 Bob Rap Up
    23738 2010-02-24 Bob News
    23740 2010-02-24 Bill Sports
    23741 2010-02-24 Sam Weather
    23742 2010-02-24 Bill Rap Up
    23743 2010-02-24 Sam Rap Up


    I need some help with creating a SQL SELECT statement to give the Date(s) that Bill and Sam were on the "Rap Up" segment together.

    In this table the dates that would be returned are 2010-02-22 and 2010-02-24.



    Thanks
  2. #2
  3. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,118
    Rep Power
    4274
    Code:
    SELECT Date
      FROM partialtable
     WHERE Host IN ( 'Bill','Sam' )
       AND Segment = 'Rap Up'
    GROUP
        BY Date 
    HAVING COUNT(CASE WHEN Host = 'Bill' THEN 'humpty' END) > 0
       AND COUNT(CASE WHEN Host = 'Sam'  THEN 'dumpty' END) > 0
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2004
    Posts
    32
    Rep Power
    11
    Thanks for the code.

IMN logo majestic logo threadwatch logo seochat tools logo