Joined query ignoring the second part of my query

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pezholio
    New Member
    • Jun 2007
    • 22

    #1

    Joined query ignoring the second part of my query

    Hi,

    I've got two tables, one called events, which has an id field (eventid), a name field (eventname), a start date (datefrom) and an end date (date to), and another called events_to_group type, which has an event id and a group type id, which refers to another table which stores the names of various different types of events.

    What I want to do is select all the events that have a particular group type id and are current events (i.e. the start or end date is more than or equal to the current timestamp).

    Here's my query, but it seems to be returning all the events, regardless of date:

    Code:
    SELECT DISTINCT events_to_grouptype.eventid FROM events, events_to_grouptype WHERE events_to_grouptype.typeid = '2' AND ((events.datefrom >= 1205227784) OR (events.dateto >= 1205227784))
    Any help you can offer me would be great.

    Cheers
  • amitpatel66
    Recognized Expert Top Contributor
    • Mar 2007
    • 2358

    #2
    Try this:

    [code=sql]

    SELECT DISTINCT events_to_group type.eventid FROM events, events_to_group type WHERE events_to_group type.typeid = '2' AND
    events.eventid = events_to_group type.eventid
    AND ((DATE_FORMAT(e vents.datefrom, '%Y-%m-%d') >= SELECT CURDATE()) OR (DATE_FORMAT(ev ents.dateto,'%Y-%m-%d') >= SELECT CURDATE()))

    [/code]

    Comment

    Working...