Hi,
I'm trying to create a SQL query to output a Csv file for another application. The existing table is a list of line item purchases. So, if a single customer buys 3 items he would be listed in the table three times, once with each item.
How can I create the query to that a customer would only be listed once and each item purchased would be included in the same row.
Existing table example
Customer #. Name. Product. Order number
1. Smith, John. Widget 1. 1000.1
1. Smith, John. Widget 2. 1000.2
2. Doe, Jane. Widget 3. 1001.1
This is what I need
Customer #. Name. Product 1. Product 2. Product 3
1. Smith, John Widget 1. Widget2
2. Doe, Jane. Widget 3
I hope that makes sence.
Thank you,
Chris
2 2196
I am super tired haven't slept much this week but it should be something close to this:
SELECT * GROUP_CONCAT('P roduct' ORDER BY 'Product' ASC SEPARATOR '. ') AS 'Products' FROM 'table' GROUP BY 'CustomerNumber '
Your field names will differ but that's the basic idea I think...
You will definitely need to mess with the field names, and * is just there because I don't know what you have in there.
NeoPa 32,566
Recognized Expert Moderator MVP
This isn't too straightforward a concept, which makes sense as it is contrary to normalised handling of data, intrinsic to any RDBMS. That said, it has been covered before ( Combining Rows-Opposite of Union). I hope that this enables you to do what you require.
Be very careful of non-normalised ( Database Normalisation and Table structures) designs though. They can appear to make life simpler, only to bite you in the bum later on.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Ben Willcox |
last post by:
Hi I am having difficulty writing an SQL query to do what I want:
I have 1 table with 2 columns, 'id' and 'name':
tbl_names:
id name
-- ----
1 Bob
2 Jeff
3 Fred
|
by: PPT33R |
last post by:
The MS Access website is very unhelpful on this topic, and I cannot
find anything in my Googling to find a hint.
I am working with very large, existing data sets that consist of
multiple fields. Two of the fields are "Origin" and "Destination".
These fields contain the FAA Airport Codes, so the data is similar. I
also have another table...
|
by: tesc |
last post by:
I am so aggravated and need any help I can get. I am using Access 2000
and am trying to sort multiple fields in a select query.
My query is set up as follows:
FIELD 1 FIELD 2 FIELD 3 FIELD4 FIELD 5 FIELD 6
MSA03 MSA 02 % change ICU 03 ICU 02 % change
calc. calc.
This format continues and in...
|
by: JIM.H. |
last post by:
Hello,
I am suing SELECT * from MyTable in a stored procedure and populate dropdown
list. By using followings:
ddlSP.DataSource = DS;
ddlSP.DataTextField = "PName";
ddlSP.DataValueField = "PID";
ddlSP.DataBind();
This show PName in dropdown list, It is working fine. Now I need to combine
PName, Field1 and Field2 as “PName: Field1 –...
|
by: JP SIngh |
last post by:
Hi All
This is a complicated one, not for the faint hearted :) :) :)
Please help if you can how to achieve this search.
We have a freetext search entry box to allow users to search the database. I
am searching two tables.
SELECT TapeRecords.Id, TapeRecords.ItemTitle, TapeRecords.SourceRef,
| |
by: mkjets |
last post by:
I have worked for hours on trying to find a solution and have not
figured it out. I am working in Access 2003. I need to create a query
that takes values from 1 table and displays them in multiple fields. I
don't have the option of changing the structure of the existing tables
because I am importing them from a separate data source on a...
|
by: nsymiakakis |
last post by:
Hello everyone, I know Access fairly well, but I am very, very weak on SQL. I have a very large table that I need to pull a grand Total from multiple fields. I have created a query to SUM all the fields individually, but I do not know how to add all the field totals to get one Grand Total. Here are 4 fields from my query as an example.
SELECT ...
|
by: Nathan Sokalski |
last post by:
I have a Repeater that uses a DataSource that has multiple fields. When the
values of these fields is displayed in the Repeater, there are fields that
are used in combination with other fields as well as by themselves. For
example, there may be a firstname field that is used in combination with a
lastname field as well as by itself. Using it...
|
by: bonneylake |
last post by:
Hey Everyone,
Well i am not sure if this is more of a coldfusion problem or a javscript problem. So if i asked my question in the wrong section let me know an all move it to the correct place.
what i am trying to display previously entered multiple fields. I am able to get my serial fields to display correctly, but i can not display my...
|
by: abirch |
last post by:
Hey. So the problem that I'm running into involves auto-numbering invoice numbers. My boss has 3 tables, 2 of which are only to temporarily store information, but when she goes to create a new invoice number, it doesn't take into consideration all three tables, and therefore she is getting repeat invoice numbers - a real nightmare.
To fix...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |