[英]SQL query and string search
I have that database diagram (MySQL). 我有那个数据库图(MySQL)。 Each
Book
has assigned a BookLanguage
. 每
Book
都分配了一个BookLanguage
。 Each BookLanguage
has two different LanguageNames
(the globalization purpose). 每个
BookLanguage
具有两个不同的LanguageNames
(全球化目的)。 And also, each Book
can have an additional BookLanguage
(but it's not required) . 而且,每
Book
可以具有一个附加的BookLanguage
(但不是必需的) 。
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
. 这就是问题所在-我在构建用于查询
Books
的SQL查询时陷入了BookLanguageNames
有一些字符串。 It's simple to build the query with joining the BookLanguage
and BookLanguageNames
but how to cope with the AdditionalBookLanguages
? 通过
BookLanguage
和BookLanguageNames
来构建查询很简单,但是如何处理AdditionalBookLanguages
?
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
: 具有三个表
Book
, BookLanguageName
(它们与您的结构相似),并且不是AdditionalBookLanguage
和BookLanguage
具有“查找表” BookLanguage
:
Book
- here you keep all the information about the books. Book
-在这里您保留了有关书籍的所有信息。 BookLanguage
- only three columns: BookID, BookLanguageID (or Code) and a boolean is_additional. BookLanguage
仅三列:BookID,BookLanguageID(或代码)和一个布尔值is_additional。 BookID and BookLanguageID would be a composite primary key. Language
- here you keep all information related to a particular language. Language
-在这里,您保留与特定语言有关的所有信息。 In such case, writing query would be easier. 在这种情况下,编写查询会更容易。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.