Left Join multiple tables

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Petre Agenbag

    #1

    Left Join multiple tables

    Hi List
    Me again.

    I'm trying to return from multiple tables, the records that have field
    "information_se nt" between two dates.
    The tables are all related by means of the id of the entry in the main
    table, ie..

    main
    id entity_name ...

    fof
    id_fof id information_sen t ...

    pub
    id_pub id information_sen t ...

    etc.

    So, I tried the following join

    select * from main
    left join fof on main.id = fof.id
    left join pub on main.id = pub.id
    left join gov on main.id = gov.id
    left join med on main.id = med.id
    left join ngo on main.id = ngo.id
    left join own on main.id = own.id
    left join sup on main.id = sup.id
    left join tra on main.id = tra.id
    where (
    (fof.informatio n_sent > '$date1' and fof.information _sent < '$date2')
    OR
    (pub.informatio n_sent > '$date1' and pub.information _sent < '$date2')
    OR
    (gov.informatio n_sent > '$date1' and gov.information _sent < '$date2')
    OR
    (med.informatio n_sent > '$date1' and med.information _sent < '$date2')
    OR
    (ngo.informatio n_sent > '$date1' and ngo.information _sent < '$date2')
    OR
    (own.informatio n_sent > '$date1' and own.information _sent < '$date2')
    OR
    (sup.informatio n_sent > '$date1' and sup.information _sent < '$date2')
    OR
    (tra.informatio n_sent > '$date1' and tra.information _sent < '$date2')
    )
    order by entity_name


    BUT, although it seems to be "joining" the tables correctly AND only
    returning the ones with the correct date criteria, it does NOT return
    the "id" or the "information_se nt" fields correctly ( due to duplication
    in the result )

    What am I doing wrong?

    Thanks


    mysql, query



    --
    MySQL General Mailing List
    For list archives: http://lists.mysql.com/mysql
    To unsubscribe: http://lists.mysql.com/mysql?unsub=m...ie.nctu.edu.tw

Working...