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?

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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.