One to many on single row

user2486993

I have an access database with a contact and phone number table. Each contact can have between 0 and 10 phone numbers. I'm trying to get all of the number for each contact on the same row in order to import as a .csv to another system. I've tried using a pivot but ran into issues since each contact has a varying number of phone numbers.

PaulFrancis

So based on your description, you have a Contacts table like,

tbl_Contacts
````````````
contactID   |   contactName
------------+---------------
1           |   Jones
2           |   Jackson

A phone record of customers like,

tbl_PhoneRecords
````````````````
phoneID |   contactID   |   contactNumber
--------+---------------+-----------------
1       |   1           |   555-555-5555
2       |   1           |   555-444-7777
3       |   2           |   111-111-1111

And your desired output be like,

qry_Output
``````````
contactID   |   contactName |   joinedContact
------------+---------------+-------------------------------
1           |   Jones       |   555-555-5555, 555-444-7777
2           |   Jackson     |   111-111-1111

You might be able to make use of Allen Browne's Code Concat Related. So your SQL would be something like,

SELECT 
    tbl_Contacts.contactID,
    tbl_Contacts.contactName,
    ConcatRelated("contactNumber", "tbl_PhoneRecords", "contactID = " & tbl_Contacts.contactID) As joinedContact
FROM
    tbl_Contacts;

Hope this helps !

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

MySQL EAV SELECT one-to-many single row results

From Dev

MySQL and PHP One to Many Return Data in Single Row, Multiple Columns

From Dev

MYSQL Single query to retrieve both single row from one table and many rows as a single field from another

From Dev

Does SQL Server execute many UPDATE requests on single row as ONE single UPDATE?

From Dev

mysql one to many in one row

From Dev

Turn many to many relationship into single row

From Dev

One-to-many relationships: how to return several columns of a single row of the child table?

From Dev

Import Many Text Files into Single Excel Sheet: One Per Row, Filename in Col. A, Contents in B

From Dev

Many rows into one row (Matlab)

From Dev

Making one row many rows

From Dev

Many rows into one row (Matlab)

From Dev

SQL - Convert one-to-many into one row

From Dev

JPA or JPQL how to return single row from a many to many relationship

From Dev

SQL Server : many-to-Many Join into Single Row

From Dev

One single output file for many regressions

From Dev

Condense multiple rows into one single, for many instances

From Dev

Delete a single entry in many to one relationship Hibernate

From Dev

jooq single query with one to many relationship

From Dev

Hg : join many repositories into a single one

From Dev

clearing many MATLAB functions in one single file

From Dev

Multiple one to many association for a single model

From Dev

Opposite of 'summarise' in dplyr: turn one row into many

From Dev

Opposite of 'summarise' in dplyr: turn one row into many

From Dev

Excel one row to many, based on column data

From Dev

HQL one to many select single object in single query

From Dev

Many to many with extra column only returns one row

From Dev

Joining columns of one row as a single ouput in MySQL

From Dev

How to extract one single row in code igniter?

From Dev

Combining multiple rows into one single row

Related Related

  1. 1

    MySQL EAV SELECT one-to-many single row results

  2. 2

    MySQL and PHP One to Many Return Data in Single Row, Multiple Columns

  3. 3

    MYSQL Single query to retrieve both single row from one table and many rows as a single field from another

  4. 4

    Does SQL Server execute many UPDATE requests on single row as ONE single UPDATE?

  5. 5

    mysql one to many in one row

  6. 6

    Turn many to many relationship into single row

  7. 7

    One-to-many relationships: how to return several columns of a single row of the child table?

  8. 8

    Import Many Text Files into Single Excel Sheet: One Per Row, Filename in Col. A, Contents in B

  9. 9

    Many rows into one row (Matlab)

  10. 10

    Making one row many rows

  11. 11

    Many rows into one row (Matlab)

  12. 12

    SQL - Convert one-to-many into one row

  13. 13

    JPA or JPQL how to return single row from a many to many relationship

  14. 14

    SQL Server : many-to-Many Join into Single Row

  15. 15

    One single output file for many regressions

  16. 16

    Condense multiple rows into one single, for many instances

  17. 17

    Delete a single entry in many to one relationship Hibernate

  18. 18

    jooq single query with one to many relationship

  19. 19

    Hg : join many repositories into a single one

  20. 20

    clearing many MATLAB functions in one single file

  21. 21

    Multiple one to many association for a single model

  22. 22

    Opposite of 'summarise' in dplyr: turn one row into many

  23. 23

    Opposite of 'summarise' in dplyr: turn one row into many

  24. 24

    Excel one row to many, based on column data

  25. 25

    HQL one to many select single object in single query

  26. 26

    Many to many with extra column only returns one row

  27. 27

    Joining columns of one row as a single ouput in MySQL

  28. 28

    How to extract one single row in code igniter?

  29. 29

    Combining multiple rows into one single row

HotTag

Archive