473,387 Members | 1,859 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,387 software developers and data experts.

SQL Statement Problem Missing Data

dcharnigo
Here is my database layout:

Institution:
...inst_id
...inst_name

IsUser:
...user_id
...login
...Institution_inst_id

Membership:
...IsUser_user_id
...Role_role_id

Role:
...role_id
...Institution_inst_id
...role_name

The Database is the back end for an application. When a user is created they are NOT assigned a role. But this can be done later. I need to return all users and associated information from the other tables. I can do this for all users in a role using the membership table, the problem is the users that are not assigned a role are not in the membership table and I have nothing to join on. any ideas? here is my working SQL that returns users in a role:

("SELECT i.user_id, i.login, r.role_name, r.role_id, t.inst_name, t.inst_id from IsUser i, Role r, Membership m, Institution t where i.user_id = m.IsUser_user_id and r.role_id = m.Role_role_id ORDER BY t.inst_name, r.role_name")

I have a feeling I may have to Use two different SQL statements, but I would like to do the job in one.

Also IsUser.Institution_inst_id --> Role.Institution_inst_id --> Institution.inst_id

Thanks for the help.
Feb 15 '07 #1
2 2031
ronverdonk
4,258 Expert 4TB
Welcome to The Scripts!

Use the LEFT JOIN. That way it will display all users and the missing values will be replaced by NULLS.

Look at this thread to see a similar problem http://www.thescripts.com/forum/thread599419.html

Ronald :cool:
Feb 16 '07 #2
Welcome to The Scripts!

Use the LEFT JOIN. That way it will display all users and the missing values will be replaced by NULLS.

Look at this thread to see a similar problem http://www.thescripts.com/forum/thread599419.html

Ronald :cool:
Thanks for the help her is my end result:

SELECT i.user_id, i.login, i.Institution_inst_id, t.inst_name, m.Role_role_id, r.role_name
FROM IsUser AS i
LEFT JOIN Institution AS t ON (i.Institution_inst_id=t.inst_id)
LEFT JOIN Membership AS m ON (i.user_id=m.IsUser_user_id)
LEFT JOIN Role AS r ON (m.Role_role_id=r.role_id)
Apr 5 '07 #3

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

Similar topics

1
by: jbaker | last post by:
I have run an statement event monitor and am digging through the data it produced. Some of the rows in the stmt table have me perplexed. These records have a stmt_text that is blank with a...
15
by: sara | last post by:
Hi I'm pretty new to Access here (using Access 2000), and appreciate the help and instruction. I gave myself 2.5 hours to research online and help and try to get this one, and I am not getting...
10
by: Mike | last post by:
I know this sounds strange but I am at a loss. I am calling a simple funtion that opens a connection to a SQL Server 2000 database and executes an Insert Statement. private void...
14
by: Siv | last post by:
Hi, I just discovered that if in an ADO.NET query I use: "Select * from Invoices Where InvoiceDate BETWEEN StartDate AND EndDate;" In this case StartDate would be 1st of month and EndDate...
7
by: Cindy H | last post by:
Hi I'm having a problem getting the insert statement correct for an Access table I'm using. The Access table uses an autonumber for the primary key. I have tried this: INSERT INTO Tournaments...
2
by: Robert Bravery | last post by:
Hi all, Being new to C# and .net I often don't know how to use things. I have created an app that imports excel data, it works well, with methods to open excel, extract the data and close excel....
6
by: dmonroe | last post by:
hi group -- Im having a nested inner join problem with an Access SQl statement/Query design. Im running the query from ASP and not usng the access interface at all. Here's the tables: ...
1
by: Ryan | last post by:
Hi, I'm trying to do retrieve some data from a table where the content is in Greek, however, the query is not working. It's a very simple statement, but I'm missing something. Here is the...
1
by: gilesy | last post by:
Hi, I have a ploblem with an insert statement using an access database, I have the same code with a sql database which works but it doesn't seem to work on access. Could someone please help. For...
3
by: gilesy | last post by:
Hi, I have a ploblem with an insert statement using an access database, I have the same code with a sql database which works but it doesn't seem to work on access. Could someone please help. For i =...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.