64 users online (1 members and 63 guests)  


  Results 1 to 3 of 3

Related

  1. Replies: 1
  2. MySQL query    Forum: PHP Forum
    Replies: 1
  3. mysql query / function problem....    Forum: Databases
    Replies: 7
  4. Replies: 4
  5. Replies: 0
  1. #1
    mikelindsey's Avatar
    New User

    Status
    Offline
    Join Date
    Jan 2010
    Posts
    3

    Smile help with mysql query

    Hello,

    I'm looking for help with a query.

    Here's the table structure

    TableA
    ida
    field1
    field2

    TableB
    idb
    field1
    field2


    TableL (lookup for TableA and TableB)
    ida
    idb


    I need to pull back a join of TableA and TableB
    but only records in which TableL has all possible
    combinations.

    So for example

    TableA
    ida=1
    ida=2

    TableB
    idb=1
    idb=2
    idb=3
    idb=4

    TableL
    ida=1 idb=1
    ida=1 idb=2
    ida=1 idb=3
    ida=1 idb=4

    So because ida=1 has a lookup entry in TableL for all possible entries in TableB I'd like to pull back a join of TableA and TableB for ida=1.

    Thanks in advance!
    Last edited by mikelindsey; 01-03-2010 at 04:12 PM.

  2. #2
    mikelindsey's Avatar
    New User

    Status
    Offline
    Join Date
    Jan 2010
    Posts
    3

    Re: help with mysql query

    Ok - think I figured it out.

    Please let me know if there is an issue
    with this.

    select a.*,b.id,count(*) from l
    inner join b on b.id=l.idb
    inner join a on a.id=l.ida
    group by a.id
    having count(*) = (select count(*) from b)

  3. #3
    jthayne's Avatar

    Status
    Offline
    Join Date
    Aug 2008
    Location
    Texas
    Posts
    508

    Re: help with mysql query

    I am not sure what exactly you were wanting to do, but the query you came up with appears correct. And if it consistently gives you the data you are looking for, then there should not be any problems with it.



Tags for this Thread