473,509 Members | 3,009 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to pull multiple fields into one query row?

1 New Member
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
Feb 19 '11 #1
2 2188
NetDynamic
27 New Member
I am super tired haven't slept much this week but it should be something close to this:

SELECT * GROUP_CONCAT('Product' 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.
Feb 19 '11 #2
NeoPa
32,557 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.
Feb 20 '11 #3

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

Similar topics

3
8783
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
2
2131
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....
3
3449
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 ...
3
3140
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";...
5
4170
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...
3
30269
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...
11
2341
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...
2
2662
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...
482
27259
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. ...
2
2298
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...
0
7234
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
7136
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
7412
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...
1
7069
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
7505
tracyyun
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...
0
5652
agi2029
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,...
1
5060
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...
0
3216
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
441
bsmnconsultancy
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...

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.