简体   繁体   English

SQL查询和字符串搜索

[英]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 ? 通过BookLanguageBookLanguageNames来构建查询很简单,但是如何处理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 : 具有三个表BookBookLanguageName (它们与您的结构相似),并且不是AdditionalBookLanguageBookLanguage具有“查找表” BookLanguage

  1. Book - here you keep all the information about the books. Book -在这里您保留了有关书籍的所有信息。
  2. 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. BookID和BookLanguageID将是一个复合主键。
  3. 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM