473,405 Members | 2,310 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

How to query from multiple tables where one table may not have data

denjermen
If anybody can help me with this I will be forever grateful. I'm no programmer nor SQL expert, but weekly I have to run a report compiling data from several tables into an excel spreadsheet. I figured I could just write a simple SQL to do that for me. Man, was I wrong. Here is what I have:

SELECT re_prop.glc, pm_master.projid, re_prop.addr1, re_prop.city, re_prop.state, re_prop.puse, re_disposition.source_list, pm_master.projtype, re_disposition.status, re_lease.curr_term_dt, pm_master.projdescription, re_disposition.disp_year, re_disposition.disp_month, re_prop.gsf, re_disposition.dispose_sqft, re_prop.acres, re_disposition.disp_acres, re_disp_financial.gross_sale, re_disp_financial.npt_gain_land, re_disp_financial.npt_loss_land, re_disposition.in_market_dt, re_disposition.under_contract_dt, re_disposition.proj_comp_dt, re_disposition.reo_dir, re_disposition.trans_spec, re_disposition.comments, pm_master.projid, pm_master.projcomment, re_disposition.proj_owner
FROM re_disposition
left join pm_master on re_disposition.data_id=pm_master.data_id
left join re_prop on re_disposition.data_id=re_prop.data_id
left join re_lease on re_disposition.data_id=re_lease.keyid
inner join re_disp_financial on re_disposition.recid=re_disp_financial.dispid
WHERE re_prop.state in ('AL','FL','GA','KY','MS','TN','IL','IN','MI','NC' ,'SC','OH','WI','WV') and re_prop.status in ('A', 'S') and re_disposition.source_list = 'PROJECT X' and re_disposition.status in ('COMPLETED','PENDING','APPROVED','IN DEVELOPMENT') and pm_master.projtype in ('Sale','Partial Sale','Lease Termination') and pm_master.statuscode in ('P','D', 'H')

As you can see, I have to combine info from different tables for this report. My problem comes at the end, where I'm trying to limit the data to the type of project (pm_master.projtype) and to the project's status (pm_master.statuscode). In pm_master, there are several "projects" under the same data id, so by limiting it to the projects I need, I will not get info from projects that do not pertain.

However, my problem occurs when there has not been a project set-up in pm_master. Normally a LEFT JOIN will show the proj because it's in the re_disposition table, but when I add the criteria for pm_master and no projects has been set-up in pm_master, the query result does not show the project in re_disposition at all.

I've tried using NULL and '' to no avail.... I'm going crazy over this and it's become an obsession of sorts.

Can anybody help me with this? I've been looking around the net for almost two weeks now and have not been able to find a solution. Once again, your help is greatly appreciated!
Oct 11 '07 #1
4 2485
code green
1,726 Expert 1GB
However, my problem occurs when there has not been a project set-up in pm_master. Normally a LEFT JOIN will show the proj because it's in the re_disposition table, but when I add the criteria for pm_master and no projects has been set-up in pm_master, the query result does not show the project in re_disposition at all
If I follow this correctly, why can you simply not remove the criteria?
Oct 12 '07 #2
If I follow this correctly, why can you simply not remove the criteria?
First off, thank you for looking into this issue for me. Yes, you are correct, if I remove the criteria, the info will show, but my dilema is that there are multiple projects under the pm_master table that does not pertain. The pm_master table keeps tracks of the status of projects for the properties. There are numerous projects for each property, some of which have been completed, others are for projects that do not pertain to the subject matter. I need to pull up projects that are the types listed: 'Sale','Partial Sale','Lease Termination' and are in status 'P','D',etc..

But, like I said, there are some projects in re_disposition that does not have a corresponding project set-up in pm_master and hence my dilema. If I do not put in the critera, I get results from other projects that do not pertain or have been completed. If I put in the criteria, I do not get the projects in re_disposition because there is no corresponding project in pm_master.

I will like to be able to pull all of the projects in re_disposition and if there is a corresponding project under the given criteria, for it to limit the projects to the criteria, but if there is not a corresponding project in pm_master, then to just list the project in re_disposition and leave the info that would've been in pm_master blank.

Once again, thanks for looking at this!
Oct 12 '07 #3
code green
1,726 Expert 1GB
Sounds a complicated situation.
I don't really have time to study your dilemma as I am going on holiday today.
But it looks like an extra field may help. Can you modify the database?
If so insert a field called say `projects_pertaining`,
then you could apply an integer code to each record denoting the common projects or under which manager it belongs or anything you like.
A sub-table called say `project_identifier` could list all the codes along with a description.
A bit of a cop-out I know but it would be a powerful way of grouping projects of certain types, managers or relevance.
Sorry if I am way off the mark here but your explanation is rather involved
Oct 15 '07 #4
Thanks for looking at the issue anyway... Anybody else with a suggestion???
Oct 17 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Rigga | last post by:
Hi, I am new to mysql and need help on how to join tables. I have a database which contains 4 tables, the main table contains information by date order and the other 3 contain data also in date...
4
by: | last post by:
I have an ACCESS db from a DEXA machine (bone scanner). The data is in seperate tables and I want to link them so that I can query and create one table with all the data I need from the seperate...
1
by: Charlie | last post by:
Hello, I have data in an Access table that I would like to export to multiple HTML tables. I would like to split the data in the Access table (about 92,000 records) into multiple HTML...
10
by: Marizel | last post by:
I'm not sure there's an easy solution to this, but thought I'd ask. I often find myself with a query which I'd like to reuse, but with a different datasource. These datasources generally have...
3
by: Matthew Kramer | last post by:
How would be the best way to do this in Access? I have two tables. The first table has all the rows of data. The first column of this table has a country name, the second has a year and the...
5
by: mimo | last post by:
Hello, I have seen samples on how to pull data from one table and save back to it using the Form View control. How do I pull from multiple tables and save back to multiple tables on one...
2
by: Allen Anderson | last post by:
Hi, I'm trying to design contact (names and addresses) tables in an Access database. Some of the contacts represent vendors, some are board members of the organization, some are donors, some...
3
by: mkjets | last post by:
I have worked for hours on trying to find a solution and have not figured it out. I am working in Access 2003. I need to create a query that takes values from 1 table and displays them in...
6
by: MVM | last post by:
Hi, I am attempting to run a query in MS SQL server between two tables that have a one to many relationship. The tables are linked on GID. What I want is one instance of every record from Table...
0
by: The Frog | last post by:
Hello Everyone, I have been asked to try and create a single SQL query to retrieve product information from a database. The way that data is arranged is that in some tables there are user...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.