CodingEasy MySQL probably :(

 

Press Ctrl+Enter to quickly submit your post
Quick Reply  
 
 
  
 From:  steve  
 To:  ALL
30083.1 
BID | LID
1      2
1      5
1      8
1      11
2      5
2      7
3      11


(BID links to a proper table with stuff)

Help :C

I want a query which, when passed *two* different "LIDs" will return with all the BIDs that have both of those.

So.. uh..

SELECT * FROM BUM :@ WHERE (lid = *2* AND lid = *8*)

Would return BID /1/. As it is against both 2 and 8.

-

I can't think of a better way to explain it :( And I can't think of what to Google for XD ASK ME QUESTIONS AND WE WILL DETERMINE WHAT I MEAN :$

0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  steve     
30083.2 In reply to 30083.1 
I think it's either this:

SQL code:
 
SELECT bid, COUNT(*) AS lid_count
FROM TABLE
WHERE lid IN (2,8)
GROUP BY bid
HAVING lid_count > 1


Or this:
SQL code:
 
SELECT bid
FROM TABLE
WHERE lid IN (2,8)
GROUP BY bid
HAVING COUNT(*) > 1


Or something along those the lines.

The key bit is the HAVING - it's like a WHERE for GROUP BYs.
0/0
 Reply   Quote More 

 From:  beseku  
 To:  steve     
30083.3 In reply to 30083.1 
SQL code:
SELECT a
FROM bum
WHERE b IN (5, 7)
GROUP BY a
HAVING COUNT(*) > 1

Ben.
-------------------------------
beseku.com
beyondstandards.com
flickrshow.com

0/0
 Reply   Quote More 

 From:  beseku  
 To:  beseku     
30083.4 In reply to 30083.3 
Bugger

Ben.
-------------------------------
beseku.com
beyondstandards.com
flickrshow.com

0/0
 Reply   Quote More 

 From:  steve  
 To:  Peter (BOUGHTONP)     
30083.5 In reply to 30083.2 
The bottom one worked thankyou :D

Now I shall just study them so I can learn what they mean :$ *has only just figured out JOINS*

0/0
 Reply   Quote More 

 From:  steve  
 To:  beseku     
30083.6 In reply to 30083.3 
Thankyou too ^_^

Now! I may aswell ask, as I think this may be a join :$

I have a table where BID actually means something, and it's those records I'd like retreived. This table for this scary LID and BID thing is one that links them ^_^

I have mastered joins on normal queries :$ But I fear this may be more complicated XD

0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  steve     
30083.7 In reply to 30083.6 
I think this is what you want...

sql code:
SELECT *
FROM second_table
WHERE bid IN (
              SELECT bid
              FROM first_table
              WHERE lid IN (2,8)
              GROUP BY bid
              HAVING COUNT(*) > 1
             )
0/0
 Reply   Quote More 

 From:  steve  
 To:  Peter (BOUGHTONP)     
30083.8 In reply to 30083.7 
Aaaaaaaah! Awesome! Thankyou! I didn't know you just put a whole query in another query :O

IS THAT CALLED A SUBQUERY? :O

*awaits ben's reply*

0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  steve     
30083.9 In reply to 30083.8 
No, it's called a Disilekad.





(Yes, it's a subquery)
0/0
 Reply   Quote More 

Reply to All    
 

1–9

Rate my interest:

Adjust text size : Smaller 10 Larger

Beehive Forum 1.5.2 |  FAQ |  Docs |  Support |  Donate! ©2002 - 2024 Project Beehive Forum

Forum Stats