Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ms Access Query: Concatenating Rows through a query

Suppose I have table in Ms Access with following information:

ColumnA ColumnB 1       abc 1       pqr 1       xyz 2       efg 2       hij 3       asd 

My question is, how can I concatenate the values in the second column to a row value based on the first column. The query results that I want is as follows:

ColumnA ColumnB 1       abc, pqr, xyz 2       efg, hij 3       asd 

I want to achieve this through a query. Can someone help me attain this?

like image 940
reggie Avatar asked Apr 01 '11 18:04

reggie


People also ask

How do I concatenate data in an Access query?

To do this, open your query in design mode. Enter your field names in the query window separated by the & symbol. This query will return the concatenation of the FirstName field , a space character, and the [LastName] field. The results will be displayed in a column called Expr1.

How do I combine two fields in Access query?

When you want to combine the values in two or more text fields in Access, you create an expression that uses the ampersand (&) operator. For example, suppose that you have a form that is called Employees.

How do you merge rows in access?

Click the "Arrange" tab, and then click the "Merge" button in the Merge/Split group to merge your selected fields into one.

How do you join fields in Access?

You create an inner join by dragging a field from one data source to a field on another data source. Access displays a line between the two fields to show that a join has been created. The names of the tables from which records are combined. The names of the fields that are joined.


1 Answers

You need a function to do the concatenation.

Microsoft Access condense multiple lines in a table

Example using your data:

Select T.ColumnA   , GetList("Select ColumnB From Table1 As T1 Where T1.ColumnA = " & [T].[ColumnA],"",", ") AS ColumnBItems From Table1 AS T Group By T.ColumnA; 
like image 54
Thomas Avatar answered Sep 18 '22 19:09

Thomas