473,387 Members | 1,504 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.

Selecting distinct values from joined table

Hi,

I want to join two tables together and only select the rows that don't have the same customer first name and last name (see my code below). When I run my code with the DISTINCT keyword, it still returns me all of the rows probably because it requires each column to be the same in order to find distinct rows, but I want the rows just as long as the customer first and last names are different from other customers:

Expand|Select|Wrap|Line Numbers
  1. use AppDb
  2. SELECT Customers.CustomerFirstName, Customers.CustomerLastName, Products.ProductName, Transactions.Quantity, Transactions.OrderTotal, Transactions.PaymentMethod, Transactions.OrderDate
  3. FROM Customers
  4. JOIN Transactions
  5.     ON Customers.CustomerNo = Transactions.CustomerNo
  6. JOIN Products
  7.     ON Products.ProductID = Transactions.ProductID
  8.  
This doesn't work either when I use the DISTINCT keyword:

Expand|Select|Wrap|Line Numbers
  1. use AppDb
  2. SELECT DISTINCT Customers.CustomerFirstName, Customers.CustomerLastName, Products.ProductName, Transactions.Quantity, Transactions.OrderTotal, Transactions.PaymentMethod, Transactions.OrderDate
  3. FROM Customers
  4. JOIN Transactions
  5.     ON Customers.CustomerNo = Transactions.CustomerNo
  6. JOIN Products
  7.     ON Products.ProductID = Transactions.ProductID
I don't care if the Products.ProductName or Transactions.Quantity etc. are equal just as long as the Customers.CustomerFirstName and Customers.CustomerLastName are not equal to other customers, so that I won't get multiple entries for the same customer, how do I go about doing this?
Mar 18 '08 #1
1 2656
Delerna
1,134 Expert 1GB
Hi sampalmer21
The customers table has 1 entry per customer right?
The Transaction table can have many entries for a particular customer, right?

Therefore the join will always re-produce the customer in the result. Once for each entry for that customer in the transaction table.

If you need the customer to be in the result recordset once only then you will need to summarise the transaction table in some way so that there is only one record per customer there also.
So the question is, how would you like to summarise the transactions?
Mar 18 '08 #2

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

Similar topics

2
by: Matik | last post by:
Hello everyone, Small and (I think) very simple quesiton;-) which makes me creazy. Let's say I have two tables listed below: T1 ==== IDX ==== 1
2
by: KoliPoki | last post by:
Greetings. I'm having a little trouble with a query. The idea is simple I need to display a list of recently unique visited URLs and the last time I visited. I have 2 table one stores the...
4
by: Lucius | last post by:
Hello everyone, I have a query problem. I'll put it like this. There is a 'publishers' table, and there is a 'titles' table. Publishers publish titles (of course). Now I want to make a query (in...
9
by: Kelvin | last post by:
Okay so this is baking my noodle. I want to select all the attritbutes/fields from a table but then to excluded any row in which a single attributes data has been duplicated. I.E. Here's my...
8
by: Henrik Larsson | last post by:
Hi, I need help with selecting the following rows from a table looking like this: ID IP Query 1 -> 1 2.2.2.2 (ie first IP 1 1.1.1.1 <- Query 2 for each...
1
by: Andy | last post by:
Hi Gang I have a simple single table that has many duplicate rows in them. The distinctrows only works on more than one table. Is there a quick and easy way to select only the distict rows...
4
by: monomaniac21 | last post by:
hi! is it possible to do the aforementioned query - selecting only distinct in 1 col but retrieving all other cols at the same time. regards marc
4
by: J | last post by:
I am editing a pre-existing view. This view is already bringing data from 40+ tables so I am to modify it without screwing with anything else that is already in there. I need to (left) join it...
7
by: swami | last post by:
What is the query for selecting non duplicate elements for eg: no name age 1 siva 28 2 blair 32 3 mano 28 i want to select blair which hasn't got any duplicate...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.