Consider an Internationale website. Let's say this website got some articles. Articles got some common parts between every localized website.
Like for example: ArticleID, Data, Author, CategoryID
+a field (or more) that contains the localized text for this article.
How would you design this table? 2 tables: the first containing the shared article "meta data" (look up) and the other containing a record for every localized version? Like this:
LocalizedID text language ArticleID
1 "text in EN" "en" 1
2 "text in FR" "fr" 1
or a big table containign metadata + localized text? like this:
ArticleID - Data - Author - CategoryID - LocalizedID - TextEN - TextFR - etc
(consider the database is not huge, less than 50.000 articles)
thanks everyone
I think you should go for the first option.. if you ever want to expand (more languages or something) it is easier...
Related
When debugging the SpellEffects.cpp in AzerothCore I found spell_id for example 2006 for level 1 resurrection priest spell and 10880 for level 3. There is a spell_ranks table that relates the two. However I cannot find the additional spell data for either of them. There is a spell_dbc table that seems to contain many columns for spell attributes but these spells do not exist there under ID column where ID = 2006 or ID = 10880.
Where is the data for those spells? specially damage(heal), mana cost, and casting time?
spell_dbc only contains overrides of spells, not the full spell list
more details about this table are available at:
https://www.azerothcore.org/wiki/spell_dbc
Thank you in advance for your help...
I want to get the parent site list/informatoin for a site based on its ID. There is a site hierarchy described in 2 tables, like this:
table: site
- id (PK)
- name
table: hierarchy
- siteid (PK) (siteid => site.id)
- parented (PK) (parented => site.id)
- topid (topid => site.id)
For example, you may have the following data in the tables:
site:
id,name
0,Earth
1,US
2,NY
3,GA
4,Queens
5,Farmers' Market
6,Buckhead
hierarchy:
siteid,parented,topid
5,4,1
4,2,1
2,1,1
1,0,1
5,6,1
6,3,1
3,1,1
1,0,1
I want to get all the parents of the Farmers's Market sites. There are markets in both Buckhead and Queens.
How do I make SQL walk / recurse up the tree to get something like this if I want the parent list for site id=5?:
site_name,parent_name
Farmers' Market,Queens
Queens,NY
NY,Earth
Farmers' Market,Buckhead
Buckhead,GA
GA,Earth
It occurs to me that there may need to be more than one row in the site table for Farmers' Market, but, I don't think so...
Thanks for your help,
David
I'm implementing a system that returns a list of available articles based on tags inserted by the user, so that the user spots the items that match (or loosely match) his criteria. The returned items will be sorted according to how likely is that they are of interest for the user. The front-end collects the tags and use them in a mySQL query (for which I'm asking hel here).
my DB has this structure:
tags(tag_id, tag_name)
articles(article_id, some_text)
articles_tags(article_id,tag_name)
an example:
the user enters the tags: "hard", "sweet", "red". mySQL will return these items, in this order:
red_candy (which is tagged as hard, red, sweet) - so 3/3 tags match
red_hammer (which is tagged as hard, red, dangerous) - so 2/3 tags match
stone (which is tagged as hard, gray) - so 1/3 tags match
pillow (which is tagged as soft, white) - 0/3 tags match
Thanks all
AC
like this:
select
distinct some_text
from
articles join article_tags on (articles.article_id = articles_tags.article_id )
join tags on (articles_tags.tag_id = tags.tag_id)
where
tag_name in ("hard", "sweet", "red")
order by count(tag_id) DESC;
gbejic's answer is perfect.
I was starting writing functions for computing scores and what not, but this is very intuitive and straightforward.
thanks a lot
AC
I am in the process of developing a database for an automated drink mixing robot, and I'm getting stuck with how to create the database.
In one table, I have a list of every possible ingredient (Coca-Cola, Pepsi, Smirnoff - Red Label, Skyy, etc.). A second table, lists which ingredients are available. A third table specifies the mixed drink recipes. My issue arises with the mixed drink table.
For example, if I wanted to order a Screw Driver, the robot would look to see if any vodka was available, and if any orange juice was available. However, if a drink recipe called for a specific type of vodka (such as Smirnoff - Red Label) I would want the robot to only use Smirnoff and not just any type of vodka.
So, does anyone have any suggestions as to how I could go about developing the database for such an application? I am thoroughly stumped with this one.
Thanks in advance.
It sounds like you need some kind of hierarchy for your ingredients. So you would have "generics" like "cola", "vodka", "rum" etc and then the "brands" like "Coca-Cola", "Smirnoff", "Bacardi" etc
One way of achieving this is with two tables:
Generics
ID - Name
1 - Cola
2 - Vodka
etc
Ingredients
ID - Generic_id - Name
1 - 1 - Coca-Cola
2 - 1 - Pepsi
3 - 2 - Smirnoff - Red Label
4 - 2 - Absolut
etc
Ps This sounds suspiciously like homework. If it is you should tag it as such...
You should add one more table "ingridient category" (ex. fruit juice, vodka, tequila) and reference ingredients table to this with FK. Then alter you receipt table, it should contain category or exact ingridient as a part of receipt.
Then, when robot looks for a ingridients it can decide, if he has exact ingridient or can choose from category list.
Split the ingredients into two tables: ingredient_types (i.e. vodka, juice, soft drink) and ingredients (i.e. Smirnoff, orange juice, cola). In the recipes reference either an ingredient type ("vodka") or specific ingredient ("Smirnoff").
I have 3 tables which allows me to get all tags of some picture, or all pictures with a specific tag.
I would like also to know the number of times each tag exist. How could I get this info using MySQL ?
Is it worth to add a "Count" column to the Tags table to hold this info ?
Files Table
File ID File Name ...
------- ---------
1 a.jpg ...
2 b.png ...
3 c.jpg ...
. .
. .
. .
Tags Table
Tag Name Tag Creator ...
-------- -----------
David david ...
2010 julia ...
. .
. .
. .
FilesTags Table
File ID Tag Name
------- --------
1 2010
1 April
1 David
2 2010
2 Julia
3 Friends
. .
. .
. .
SELECT FilesTags.Tag_name, COUNT(*) as number_of_occurences
FROM FilesTags
GROUP BY FilesTags.Tag_name;
Zaki's response answers one of your questions but not the other one.
"Is it worth to add a "Count" column
to the Tags table to hold this info ?"
It really depends on what you are going to do with the counts. Which in turn depends on the nature of your web site.
SO makes displays the counts alongside the tags; that's partly because its target audience is geeks and geeks like numbers. But also the count is useful information when it comes to tagging a question. Plus there's the Taxonomist's badge to consider, and the display of new tags on the Moderators' page. In other words, there's a lot of calls on the count, so it makes sense to hold and maintain the count against each tag.
Other sites don't extract nearly as much juice out of their tags. But, as an example, say you want to display a tag cloud; you might want to be avoid counting all the entries in FileTags each time you render it. Holding the count would then be a help.
But remember, writes can be expensive. So have a clear idea what you are going to do with the counts before you decide to store them. Maintaining them asynchronously, perhaps in a batched job, would be a good idea.
To find the number of times tag "ABC" occurs just do
SELECT COUNT(*) FROM FilesTags Table WHERE Tag Name = "ABC";
Hope this helps.