Tony
Tony

Reputation: 12695

SQL query and string search

I have that database diagram (MySQL). Each Book has assigned a BookLanguage. Each BookLanguage has two different LanguageNames (the globalization purpose). And also, each Book can have an additional BookLanguage (but it's not required).

And here's the problem - I'm stuck here while building a SQL query for searching for that Books, whose have some string in the BookLanguageNames. It's simple to build the query with joining the BookLanguage and BookLanguageNames but how to cope with the AdditionalBookLanguages ?

enter image description here

Upvotes: 1

Views: 168

Answers (1)

GregD
GregD

Reputation: 2867

How about simplifying the database design? Have three tables Book, BookLanguageName (both of them similar structure to yours) and, instead of AdditionalBookLanguage and BookLanguage have a "lookup table" - BookLanguage:

  1. Book - here you keep all the information about the books.
  2. BookLanguage - only three columns: BookID, BookLanguageID (or Code) and a boolean is_additional. BookID and BookLanguageID would be a composite primary key.
  3. Language - here you keep all information related to a particular language.

In such case, writing query would be easier.

Upvotes: 1

Related Questions