Should we always abbreviate column values like for the category column?


In this code challenge, the category column values are abbreviated as ‘b’ for ‘Business’ and ‘t’ for ‘Technology’. Should we always abbreviate column values like the category column?


This can be entirely dependent on how you choose to implement the table, and there is no right or wrong answer.

To decide whether to use abbreviations for values, you might consider a few of the following factors.

One important factor is understandability of the information. What if it was not apparent immediately that 'b' stood for ‘Business’, and 't' for 'Technology? To account for this, you may need to store the abbreviation meanings somewhere easily accessible, like another table in the database with abbreviations mapped to their full meanings. Also, what if there were multiple values that started with b, like Books? You might need to choose some way to represent any possible values as abbreviations.

Another factor you might consider is memory. Using abbreviations can have the benefit of saving memory used. For instance, the column data type can be set to some smaller data type like CHAR, which can take less memory than the TEXT data type. When you have millions, or even billions, of entries, these values start to really add up.

Everything has a tradeoff, so whichever method you choose can have some pros and cons that might be more appropriate to your needs.

 FROM news
 WHERE category = 'b'
 ORDER BY timestamp DESC
 LIMIT 20;

Why didn’t we add category = ‘b’ AND ‘t’ on the third line?


I have the same question. Hope someone can answer it.


Because the question is asking for “Business” articles only.


I made the same mistake at first, but note that that question then asks " What are the 20 business articles". I then removed the 'OR category =‘t’ 'from my formula. Hope this helps.

1 Like