User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the MySQL section within the Web Development category of DaniWeb, a massive community of 391,571 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,780 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MySQL advertiser:
Views: 436 | Replies: 1
Reply
Join Date: Jul 2008
Posts: 2
Reputation: php-lover is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
php-lover php-lover is offline Offline
Newbie Poster

select from multiple tables please help

  #1  
31 Days Ago
Hi,

It's took me a weeks to figure out this query.

I'm trying to select all the data from 7 tables but i got empty result. All these table has a link on region_id column.

Your help will be much much appreciated.

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';
If you need more information about my table then I can post it.

Thank you for your time.

Finau
Last edited by Tekmaven : 31 Days Ago at 4:12 am. Reason: Cod
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Apr 2008
Posts: 295
Reputation: tesuji is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 41
tesuji tesuji is offline Offline
Posting Whiz in Training

Re: select from multiple tables please help

  #2  
31 Days Ago
Hi Finau,

If both following statements are true

1. Each table has a column named region_id of compatible data type
2. At least one of those tables has primary key region_id AND all other
tables containing region_id that column is attributed to be foreign key.

then you may carry out this sql statement
select * from  tbl_residential_sale as rs join tbl_residential_rent as rr
         join  tbl_commercial_sale as cs join tbl_commercial_rent as cr
         join  tbl_commercial_lease as cl join tbl_land_sale as ls
         join  tbl_land_lease as ll
to get a first result. Afterwards you can add some further predicates, like cr.start_date IS NOT NULL AND cr.expire_date >= NOW()..., to where-clause for reducing result set.

I really doubt a little that each table has column region_id. You may post the creating statements of your seven tables.

Btw, your select statement seriously lacks of join constraints which must be added to where-clause, as for example: where rs.joining-column = rr.joining-colum etc. If you omit such constraints you will get a undesirable cross products (cartesian products).

-----
tesu
Last edited by tesuji : 31 Days Ago at 2:20 pm.
Information is moving—you know, nightly news is one way, of course, but it's also moving through the blogosphere and through the Internets. I promise you I will listen to what has been said here, even though I wasn't here. Ann and I will carry out this equivocal message to the world. I'm the master of low expectations.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb MySQL Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the MySQL Forum

All times are GMT -4. The time now is 10:22 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC