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

Querying two tables (1-to-many relationship)

Hi.

I have the following problem:

I have two tables:
- Customers (CustomerID, Name)
- Orders (OrderID, CustomerID, Product)

I need to create a query/report that will have the following fields:
- CustomerID, Name, OrderID

If I do it the normal way * I will end up having one line for each order and the customer name will be repeated.
Instead, I would like to have one line per customer, and then the OrderIDs separated by commas...

Is this possible using queries?

* SELECT Customers.CustomerID, Customers.Name, Orders.OrderID FROM Customers LEFT JOIN Orders ON Customers.CustomerID = Orders.CustomerID;

Any help would be greatly appreciated. Thanks!!
Feb 21 '07 #1
6 1625
Rabbit
12,516 Expert Mod 8TB
I don't think it's possible without code.
Feb 21 '07 #2
MMcCarthy
14,534 Expert Mod 8TB
This is the best I can do for you ...

Expand|Select|Wrap|Line Numbers
  1. TRANSFORM OrderID
  2. SELECT CustomerID, [Name]
  3. FROM (SELECT Customers.CustomerID, Customers.Name, Orders.OrderID
  4. FROM Customers INNER JOIN Orders 
  5. ON Customers.CustomerID = Orders.CustomerID) As CustOrders
  6. GROUP BY CustomerID, [Name]
  7. PIVOT OrderID;
  8.  
Mary
Feb 22 '07 #3
Thank you for your reply, but the crosstab query has a limited number of column headings.
Thanks very much for your help though, because I can use it elsewhere!
Feb 22 '07 #4
NeoPa
32,556 Expert Mod 16PB
Have a look in here (Combining Multiple Rows of one Field into One Result). It doesn't (can't possibly) work in columns as such, but does produce a list.
Feb 23 '07 #5
NeoPa
32,556 Expert Mod 16PB
This (Combining Rows-Opposite of Union ) is a better link - referred to in the first, but the main stuff is in here.
Feb 23 '07 #6
Michael R
176 100+
This (Combining Rows-Opposite of Union ) is a better link - referred to in the first, but the main stuff is in here.
Supertsik, let us know how are things working out for you with this problem. Thanks.
Feb 24 '07 #7

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

Similar topics

3
by: Henri | last post by:
Hello, I am quite new to ms-sql and I have a problem : I want to create an SQL request which would copy serveral records from a table in a given database to another table (with exactly the same...
2
by: Steve | last post by:
Hi; I am looking for suggestions about how to solve a problem using tsql. I have been asked to create a report concerning 4 tables. Each of the 4 tables is in its own database. The 4...
7
by: bizt | last post by:
Hi, I have an Intranet with the organisation I work with. In this organisation there are two departments - community department and press office. Both the community department and press office...
8
by: Andante.in.Blue | last post by:
Hello, I have just inherited a legacy Access 97 database. While going through it, I noticed something strange... its Relationships window (the one accessed by Tools --> Relationships) is almost...
5
by: Shane | last post by:
I wonder if someone has any ideas about the following. I am currently producing some reports for a manufacturing company who work with metal. A finished part can contain multiple sub-parts to...
7
by: francophone77 | last post by:
I deleted a relationship in the relationship view, but when I create a query that includes those two tables, the relationship reappears. When I go back to the relationship view there is NO...
3
by: kashifahmed.bse.mg | last post by:
Hello All, I would like to insert dynamically created related tables by using datatable collections in ado.net. So can anyone figure out which procedure is usefull to do this task. Example will...
10
by: Richard | last post by:
Hi folks, thanks for taking the time to read this (and hopefully point our where I'm going wrong). The scenario: I have a local Access2007 database which links in several read only mySql...
0
by: PreethiParkavi | last post by:
Hi, I am having two tables : Offer and OfferItems.Both tables having Identity fields as primary keys Offer_ID and OfferItem_ID respectively. the field "OI_OfferID" in OfferItem table relates...
0
by: imusion | last post by:
Hi, I have 2 servers each running AIX and both have a DB2 database setup on them. I'm building a news management application and in our setup we need to have a staging and production setup. So...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.