Avatar of mcrmg
mcrmg
 asked on

Query syntax

Hi,

I have two tables,

Table A has users' info, name, address.etc
Table B has notes that created by users in Table A, each user can create multiple notes.

Table A
userid
username
firstname
lastname
address

Table B
noteid
userid
note
date

I need to create an Excel report that contain all users and their notes. Since each user can create multiple notes, I want to combine individual user's notes into one cell.  Is there a way to do this in SQL stored procedure?  thanks
Microsoft SQL Server 2008SQL

Avatar of undefined
Last Comment
mcrmg

8/22/2022 - Mon
D Patel

Use This syntax:

select
  tableA.userid as `Id`,
  tableA.username as `User`,
  GROUP_CONCAT(tableB.note) as `Notes`
from
  tableA,
  tableB
where
  tableA.userid=tableB.userid
group by
  tableA.userid
YZlat

whuch databas edo you use? MS SQL? mySQL?
mcrmg

ASKER
thanks for the quick reply, I am getting

'GROUP_CONCAT' is not a recognized built-in function name.


I have SQL 2008, too old?  thanks
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
YZlat

GROUP_CONCAT is for mySQL
ASKER CERTIFIED SOLUTION
YZlat

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
Jim Horn

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
mcrmg

ASKER
thank you very much. Learned something new today