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

SQL JOIN QUERY ISSUE

Hi all,

having problem with query below

SELECT DISTINCT dbo.logon.DRIVER_NO, dbo.booking_form.DriverNo FROM
((dbo.logon RIGHT JOIN dbo.Employees ON dbo.logon.DRIVER_NO =
dbo.Employees.DriverNo) ) LEFT JOIN dbo.booking_form ON dbo.logon.DRIVER_NO
= dbo.booking_form.DriverNo

problem is it produces more than 1 result for the driver from the
booking_form table. If a Driver is logged in then I need to show information
from the booking_form table for that driver but it produces row after row of
data. Have tried all combinations of JOIN but to no avail.

How do I select the last entry in the dbo.booking_form table for the driver
logged in?.

Regards
Simon
--
Simon Gare
The Gare Group Limited

website: www.thegaregroup.co.uk
website: www.privatehiresolutions.co.uk
Apr 12 '07 #1
1 2024
Simon Gare wrote:
Hi all,

having problem with query below

SELECT DISTINCT dbo.logon.DRIVER_NO, dbo.booking_form.DriverNo FROM
((dbo.logon RIGHT JOIN dbo.Employees ON dbo.logon.DRIVER_NO =
dbo.Employees.DriverNo) ) LEFT JOIN dbo.booking_form ON
dbo.logon.DRIVER_NO = dbo.booking_form.DriverNo

problem is it produces more than 1 result for the driver from the
booking_form table. If a Driver is logged in then I need to show
information from the booking_form table for that driver but it
produces row after row of data. Have tried all combinations of JOIN
but to no avail.

How do I select the last entry in the dbo.booking_form table for the
driver logged in?.
I'm suspect this is SQL Server, but I'm not sure given the unnecessary
parentheses in your FROM clause, parentheses that would be necessary if this
were a Jet database. However, given the "dbo." qualifiers, the pendulum
swings toward SQL Server. Please don't make us guess!! Alyways tell us your
database type and version.

Having said that, we need more information about your table structures,
partidularly about their primary and foreign keys. Given the joins you used,
I can make a guess that logon seems to be the "master" table in a 1-to-many
relationship with booking_form. But I'm mystified about the relationship
between Employees and logon: is that 1-to-1 or 1-to-many? I guess you are
using outer joins because you want the query to return all Employee records,
regardless of whether they appear in logon or booking_form. Too much
guesswork here. Please see this: www.aspfaq.com/5006.

Now, your select clause only mentions fields from logon and booking_form:
why include Employees in the query if you don't want any information from
it? The only time it is appropriate to include a table in a FROM clause
without including fields from that table in the select clause is if you are
using that table to limit, group or sort the results, none of which seems to
be the case here. Most of my questions will be answered if you provide the
DDL, a few rows of sample data (in tabular form - relevant fields only,
please), and the desired resultset using that sample data, again in tabular
form.

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Apr 12 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: B. Fongo | last post by:
I learned MySQL last year without putting it into action; that is why I face trouble in formulating my queries. Were it a test, then you would have passed it, because your queries did help me...
0
by: B. Fongo | last post by:
I learned MySQL last year without putting it into action; that is why I face trouble in formulating my queries. Were it a test, then you would have passed it, because your queries did help me...
0
by: B. Fongo | last post by:
I learned MySQL last year without putting it into action; that is why I face trouble in formulating my queries. Were it a test, then you would have passed it, because your queries did help me...
33
by: Steve | last post by:
One of our clients recently upgraded their Office version to 2003. When they tried to run our program (written in Access 2000), they ended up with the wrong data. My coworker and I have tested this...
3
by: Zeff | last post by:
Hi all, I have a relational database, where all info is kept in separate tables and just the id's from those tables are stored in one central table (tblMaster)... I want to perform a query, so...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.