Sql query to test you, Im having trouble with it.. (1 Viewer)

cright99

Registered User.
Local time
Today, 15:20
Joined
Jan 17, 2009
Messages
24
I have about 4 attributes of a table called Customer which has a primary key CustomerId then FirstName, lastname, phonenumber

Then it has a relationship with another table called Application with a primary key of ApplicationId then Type, ExpiryDate, CustomerID

CUSTOMER(CustomerID, FirstName, LastName, PhoneNumber)
APPLICATION(ApplicationID, Type, ApplicationNumber, CustomerID*)


They are linked up through the customerID

What I want is to have 1 query that grabs all the customer details and only the ApplicationNumber (Which is linked up with the customerID). But if a customer doesn't have an application then it still shows that customer in the query but with a blank application number.

Thank you! I've been working on this for a while.
 

PNGBill

Win10 Office Pro 2016
Local time
Today, 15:20
Joined
Jul 15, 2008
Messages
2,271
This sql returns a blank for a staff member without an application.

PHP:
SELECT TblStaff.StaffID, TblStaff.StaffName, TblApplications.ApplicationID
FROM TblStaff LEFT JOIN TblApplications ON TblStaff.StaffID = TblApplications.StaffID;
 

RainLover

VIP From a land downunder
Local time
Today, 13:20
Joined
Jan 5, 2009
Messages
5,041
Post the SQL that you have enven thought it doesn't work.

Maybe we can fix that.
 

PNGBill

Win10 Office Pro 2016
Local time
Today, 15:20
Joined
Jul 15, 2008
Messages
2,271
With your field names it would be:

SELECT CUSTOMER.CustomerID, CUSTOMER.FirstName, CUSTOMER.LastName, CUSTOMER.PhoneNumber
FROM CUSTOMER LEFT JOIN APPLICATION ON CUSTOMER.CustomerID = APPLICATION.CustomerID;
 

cright99

Registered User.
Local time
Today, 15:20
Joined
Jan 17, 2009
Messages
24
Thank you soo much. Perfecty done :D

Quite sad as I've just completed a course on databases. But I've never been told how to use the join keyword before :(
 

Users who are viewing this thread

Top Bottom