hayleyelisa
hayleyelisa

Reputation: 359

How to return data from tables in MySQL that is not a table format?

I've looked all over the Internet and even this website for an answer, and maybe I'm just phrasing my question in a way that isn't getting me to the correct results, but I was just wondering if there's a way to use SQL to return data from tables in a way that isn't table form?

Basically, I have a table of information on different books and I want to find a way to return info in this format: "Author; Title (Publisher: Year of publication)" without using PHP or any other type of programming language? Just using SQL?

Upvotes: 0

Views: 220

Answers (2)

ljh
ljh

Reputation: 2594

This probably can help you.


select COALESCE(Author,'')+';'+COALESCE(TITLE,'') + ' ('+COALESCE(Publisher,'')+':'+cast([Year of publication]) as varchar) + ')' as Result from yourtable

Upvotes: 0

FeRtoll
FeRtoll

Reputation: 1267

You can use concat.

see example below

select concat(COALESCE(AUTHOR,''),'; ',COALESCE(TITLE,''),' (',COALESCE(PUBLISHER,''),':',COALESCE(YEAROFPUBLISH,''),')') as your_result from YOUR_TABLE

Upvotes: 1

Related Questions