Sql query to test you, Im having trouble with it..

cright99

Registered User.
Local time
Tomorrow, 08:06
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.
 
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;
 
Post the SQL that you have enven thought it doesn't work.

Maybe we can fix that.
 
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;
 
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

Back
Top Bottom