MySQL Forums
Forum List  »  Newbie

Re: Fetching multiple values with single select
Posted by: Phillip Ward
Date: July 19, 2018 08:32AM

(1) Where do these Ids come from?

I'm guessing they're the result of some other query?
If so, then combine the two queries, joining the products table to whichever other tables are required based on product id.

select imageUrl, productName 
from products p 
inner join some_other_table s 
      on   p.productId = s.productId 
. . . 
order by ...

If they come from some other source, you might try using an "in" clause, but that has [performance] problems of its own.

Quote

Is it good approach to save object by serializing it to json and saving it as string
Personally, I would say not, but then I'm still yet to be convinced that this data really is a single "object" that never needs to be dissected, queried or otherwise interrogated.

If this "object" constitutes the details of an Order then I would argue that they should be held in a Relational form to allow you to query them effectively.

Ask yourself: what am I going to do with this data?

If all you ever do is retrieve it as a single unit and throw it on a screen in front of a user, then fair enough; store it as a single entity. If you do anything more than that - search to find bits of it, interrogate what's in it, or extract parts of it - then you should be thinking about storing it as "raw" data. Databases are good at finding stuff and really good at putting together little things to make bigger things. They're actually quite rubbish at pulling big things apart.

That said, if you're determined to do so, through, then a single table with an identifier and a really big field to put the JSON into will do the trick.

Regards, Phill W.

Options: ReplyQuote


Subject
Written By
Posted
Re: Fetching multiple values with single select
July 19, 2018 08:32AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.