Forum Moderators: open

Message Too Old, No Replies

Pull back records from checking multple rows for active?

pulling my hair out

         

apauto

6:59 am on Jul 1, 2009 (gmt 0)

10+ Year Member



+------------------+----------+---------+
¦ Column1 ¦ Column2 ¦ Active ¦
+------------------+----------+---------+
¦ blue widgets ¦ 14 ¦ y ¦
¦ red ¦ 14 ¦ y ¦
¦ redx ¦ 15 ¦ y ¦
¦ blues ¦ 14 ¦ y ¦
¦ blue ¦ 15 ¦ n ¦
¦ bluesX ¦ 15 ¦ n ¦
¦ widgets ¦ 14 ¦ n ¦
+------------------+----------+---------+

Here is my drama... I need to query this:

where (Column2 = 14 AND Column2 = 15) and active = 'y'

I a result set that has all records where there is active = 'y' for both Column2=14 and Column2=15

I can't figure this out...

I can do it so it returns me 14 and 15 with at least one of them as y, but not both.

I tried:

select * from table where (Column2 = 14 and Column2 = 15) and active = 'y'

Of course, this returns nothing, since both can't be 14 and 15 at the same time.

So I tried:

select * from table where ((Column2 = 14 or Column2 = 15) and active = 'y')

And this returns a result set, but not what I want...

I need to only return results in column1 that have:

column2 = 14 and active = 'y'
column2 = 15 and active = 'y'

both conditions must be true.

Any help? thanks guys!

apauto

5:44 pm on Jul 1, 2009 (gmt 0)

10+ Year Member



Does my question make sense?

apauto

6:22 pm on Jul 1, 2009 (gmt 0)

10+ Year Member



Ok, I'm getting close...

Anyone know what is wrong with this query...

SELECT DISTINCT Vendors . * , packageFeatures.providerId, packages.pricing
FROM Vendors, packageFeatures, packages
WHERE (
Vendors.id = packages.VendorId
AND Vendors.id = packageFeatures.providerId
)
AND (
packageFeatures.providerId = (

SELECT *
FROM packageFeatures
WHERE featureId =32
AND active = 'y'
)
AND packageFeatures.providerId = (

SELECT *
FROM packageFeatures
WHERE featureId =82
AND active = 'y'
)
)
AND (
Vendors.type = 'small'
)
AND Vendors.hidden = 'n'
LIMIT 0 , 30

apauto

6:49 am on Jul 2, 2009 (gmt 0)

10+ Year Member



figured it out...