Say I have a table named "ONE" with a single column "Column1." Let the data be as below:


What will be the query to display the three records concatenated into a single row? I was unable to answer this question in an interview!! Thanks in advance.

    Requires Free Membership to View

What kind of a question is that?? The interviewer was clearly trying to rattle you, because that's a pretty dumb question. I would have been tempted to reply "The answer is available by inspection -- 'a,b,c'. Voila and QED. I don't write queries for trivialities. Now please ask me something serious, like the difference between surrogate and natural keys."

Okay, let's look at some solutions. Here's the answer in MySQL:

select group_concat(Column1)
  from ONE

Here's the answer in Sybase ASA:

select list(Column1)
  from ONE

If you're using any other database system, it gets a little harder. In Oracle, you can try some of these methods. Other databases require similar approaches.

This was first published in June 2006

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to: