0

Can I have a table cell in a view that has an array of rows or even columns from a table.

Is this possible in mysql or will one have to do another query on the webpage?

CREATE VIEW booksview AS SELECT

Authors.id AS id, Authors.name AS name, (select book from books WHERE authorId = id) AS authorsBooks, Authors.Lastname AS Lastname,

FROM Authors;

my sql sais "Operand should contain 1 column(s)". Suggesting there is a limit to one value. Is it possible to get the data returned even as a string or something in the view cell?

Lokesh Kumar Gaurav
  • 726
  • 1
  • 8
  • 24
  • https://stackoverflow.com/questions/276927/can-i-concatenate-multiple-mysql-rows-into-one-field – Christian Moen Jan 04 '18 at 19:39
  • Sounds good, i have one more question, if people were to give comments or reviews on a book, would you recommend one have a view cell with this function in it and then transform it into an array in php as apposed to selecting the comments and reviews from another table or view? Im assuming this would be much faster to retrieve from the database especially if there are loads of comments like on youtube. what are your thoughts? – Jevon McPherson Jan 04 '18 at 19:43
  • Fetch it individually. It will make it easier for you to work with :-) – Christian Moen Jan 04 '18 at 19:46

1 Answers1

1

You can do this using GROUP_CONCAT()

Credit to christian-moen

flip
  • 555
  • 3
  • 8
  • I do not think he is asking for php code to solve this problem, bud. – Christian Moen Jan 04 '18 at 19:30
  • @ChristianMoen It's just an example of what needs to be done to manipulate the data when it comes back from MySQL. Any code could be used, but ultimately what's being asked for cannot be done solely in SQL. – flip Jan 04 '18 at 19:35
  • It's sure possible. https://stackoverflow.com/questions/276927/can-i-concatenate-multiple-mysql-rows-into-one-field – Christian Moen Jan 04 '18 at 19:39
  • Please edit your answer to include the link i provided, and i'll change the downvote to an up vote instead :-) – Christian Moen Jan 04 '18 at 19:48