Select from multiple tables...please help

Discussion in 'Databases' started by php-lover, Jul 19, 2008.

  1. #1
    I was trying to fix this query but i had now luck. It's took me 3 weeks to figure it out and still no luck, please help.

    I'm trying to select all the data from 7 tables but it's return nothing from the query result. All these table has a link on region_id column.

    Here's my query:


    $q = 'SELECT rs.*,rr.*,cs.*,cr.*,cl.*,ls.*,ll.* FROM 
                   tbl_residential_sale as rs,
                   tbl_residential_rent as rr,
                   tbl_commercial_sale as cs,
                   tbl_commercial_rent as cr,
                   tbl_commercial_lease as cl,
                   tbl_land_sale as ls,
                   tbl_land_lease as ll
                   WHERE 
                   rs.start_date IS NOT NULL AND rs.expire_date >= NOW() AND rs.region_id=1
                   AND
                   rr.start_date IS NOT NULL AND rr.expire_date >= NOW() AND rr.region_id=1
                   AND
                   cs.start_date IS NOT NULL AND cs.expire_date >= NOW() AND cs.region_id=1
                   AND
                   cr.start_date IS NOT NULL AND cr.expire_date >= NOW() AND cr.region_id=1
                   AND
                   cl.start_date IS NOT NULL AND cl.expire_date >= NOW() AND cl.region_id=1
                   AND
                   ls.start_date IS NOT NULL AND ls.expire_date >= NOW() AND ls.region_id=1
                   AND
                   ll.start_date IS NOT NULL AND ll.expire_date >= NOW() AND ll.region_id=1';
    Code (markup):

    Please help I could not think anymore.

    Thank you very much.
     
    php-lover, Jul 19, 2008 IP
  2. rob_v

    rob_v Peon

    Messages:
    72
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Do a qry on each table and make sure each one brings back a record w/ the correct were clause.
    XX.start_date IS NOT NULL AND XX.expire_date >= NOW() AND XX.region_id=1

    Im betting that 1 of the tables does not have a region_id = 1 and an expire_date >=now()
     
    rob_v, Jul 20, 2008 IP
  3. php-lover

    php-lover Active Member

    Messages:
    261
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    58
    #3
    Thank you rob_v for your help. Well it's my stupid mistake...lol I try to run a select query across these tables but when I re-read my project plan, I realize that the plan I made was not about to run a select query from these table.

    Sorry, if I waste your time.

    This post is fixed.

    cheers.:)
     
    php-lover, Jul 20, 2008 IP