Jump to content

Query Database to return a single row/column with comma delimited string?


esender

Recommended Posts

I'd like to query my database such that it returns a single cell that has all my results in one Comma delimited string.

 

here is an example.

 

Normally, someone says:

 

SELECT title FROM node WHERE type = 1 LIMIT 20

 

This will return 20 separate rows:

 

"Title1"

"Title2"

...

"Title20"

 

Well, how do I query it so that it actually returns a delimited, single row, single coloum:

 

"Title1,Title2,Title3,Title4,Title5,Title6,...,Title20"

 

All in one row, one column?

Link to comment
Share on other sites

Curiously why would you want this?

You're better of keeping it as a rowed dataset, then you can manipulate any rendered output in your scripting language instead.

 

I do this because the way my table is layed out, a single node ID can correspond to multiple titles. Say, an Item is rated "best" in multiple categories.

Link to comment
Share on other sites

Curiously why would you want this?

You're better of keeping it as a rowed dataset, then you can manipulate any rendered output in your scripting language instead.

 

I do this because the way my table is layed out, a single node ID can correspond to multiple titles. Say, an Item is rated "best" in multiple categories.

 

You shouldn't keep comma delimited strings in your DB.  If you have a node with multiple titles then you should have multiple records for that node.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.