> I've got a query that I just can't get right. 
> 
> select *
> From companies
> where companyhide = 0 
> and companyid = (select distinct companyid  
>                  From releases where date_entered <=  DATE_SUB(curdate
>                  (),INTERVAL 8 day) and   date_entered >= DATE_SUB
>                  (curdate(),INTERVAL 30 day)
>                   order by  date_entered desc)
> order by rank, company
> 
> Essentially, I've got a table of companies and anothr table 
> with press releases. press releases are linked to companies 
> by company id. What I'm trying to do is select only companies 
> that have press releases within the last for weeks.  What the 
> above is giving me is a list of companuid's, whihc does not work. 
> 
> Any help or suggestion would be much appreciated.

At first glance, my initial suggestion would be to use IN instead of "=" for
your comparison:

AND companyid IN (SELECT ...

Also, there's no need to use ORDER BY in your subquery, and frankly I'd
probably write this using a JOIN instead of a subquery anyway.

SELECT          c.*
FROM                    companies c
INNER JOIN              releases r ON c.companyid = r.companyid
WHERE                   c.companyhide = 0
AND                     r.date_entered BETWEEN DATE_SUB(curdate(), INTERVAL
8 day) AND DATE_SUB(curdate(), INTERVAL 30 day)
ORDER BY                c.rank, c.company

Dave Watts, CTO, Fig Leaf Software
http://www.figleaf.com/

Fig Leaf Software provides the highest caliber vendor-authorized 
instruction at our training centers in Washington DC, Atlanta, 
Chicago, Baltimore, Northern Virginia, or on-site at your location. 
Visit http://training.figleaf.com/ for more information!


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Find out how CFTicket can increase your company's customer support 
efficiency by 100%
http://www.houseoffusion.com/banners/view.cfm?bannerid=49

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:208507
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to