Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Mar 2006
    Posts
    93
    Thanks
    3
    Thanked 0 Times in 0 Posts

    sql help for a query

    Hi, i have a table (listProfiles) that has 3 fields (id, profile, list). Say i have 5 entries in that table.
    1-1-1
    2-1-2
    3-1-3
    4-2-1
    5-2-2

    I need to do a query where i get the profile (second column) that contains the list (third column) 1 AND 2 AND 3. IF i do do something like this :
    Code:
    SELECT * FROM listProfiles WHERE list=1 AND list=2 AND list=3
    it does not work. So i want the profiles (1 in my example) that have the list 1,2 and 3 in seperate entries. Is this possible?

    Thanks

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,947
    Thanks
    79
    Thanked 4,424 Times in 4,389 Posts
    Not at all as simple as that.

    Code:
    SELECT P1.* 
    FROM listProfiles AS P1, listProfiles AS P2, listProfiles AS P3
    WHERE P1.profile = P2.profile AND P1.profile = P3.profile
    AND P1.list=1 AND P2.list=2 AND P3.list=3
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    maxpouliot (10-17-2013)


  •  

    Posting Permissions

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