简体   繁体   English

带有INNER JOIN的SQL SELECT错误

[英]Error in SQL SELECT with INNER JOIN

So, basically, I have two tables called "dadoscatalogo" and "palavras_chave", with a common field, "patrimonio" which is the primary key of "dadoscatalogo". 因此,基本上,我有两个表,分别称为“ dadoscatalogo”和“ palavras_chave”,具有共同的字段“ patrimonio”,这是“ dadoscatalogo”的主键。

I'm using a servlet to connect to the database with these tables, and passing a query to search for entries based on some search criteria that's defined by the user. 我正在使用Servlet通过这些表连接到数据库,并传递查询以根据用户定义的某些搜索条件来搜索条目。

Now, since the user can search for entries based on information present in both tables, I need to do an INNER JOIN , and then use WHERE to search for that info. 现在,由于用户可以基于两个表中存在的信息搜索条目,因此我需要执行INNER JOIN ,然后使用WHERE来搜索该信息。 I'm also using LIKE , because the user may pass just part of the information, and not all of it. 我也在使用LIKE ,因为用户可能只传递部分信息,而不是全部。

So, to test it all out, I tried passing it a few parameters to work with, and see how it went. 因此,为了进行全面测试,我尝试向其传递一些参数以供使用,然后看看它如何进行。 After some debugging, I found out that there was some mistake in the query. 经过一些调试后,我发现查询中存在一些错误。 But I can't seem to be able to point out exactly what it is. 但我似乎无法确切指出它是什么。

Here's the test query: 这是测试查询:

SELECT dadoscatalogo.patrimonio
FROM dadoscatalogo 
  INNER JOIN palavras_chave 
    ON dadoscatalogo.patrimonio=palavras_chave.patrimonio 
WHERE dadoscatalogo.patrimonio LIKE '%' 
  AND dadoscatalogo.titulo LIKE '%tons%' 
   OR palavras_chave.palchave LIKE '%programming%';

So, basically, what I'm trying to do with this query is, get all the primary keys from "dadoscatalogo" that are linked to a record with a "titulo" containing "tons", or a "palchave" containing "programming". 因此,基本上,我要对此查询执行的操作是,从“ dadoscatalogo”中获取所有主键,这些主键与包含“吨”的“ titulo”或包含“ programming”的“ palchave”链接到记录。

PS. PS。 Sorry for the names not being in English, hopefully it won't be too much of a distraction. 很抱歉,您的名字不是英文的,希望不会太让人分心。

EDIT: Right now, the tables don't have much: 编辑:现在,表没有太多:

This is the dadoscatalogo table: http://gyazo.com/fdc848da7496cea4ea2bcb6fbe81cb25 这是dadoscatalogo表格: http ://gyazo.com/fdc848da7496cea4ea2bcb6fbe81cb25

And this is the palavras_chave table: http://gyazo.com/6bb82f844caebe819f380e515b1f504e 这是palavras_chave表: http ://gyazo.com/6bb82f844caebe819f380e515b1f504e

When they join, I'm expecting it to have 4 records, and it would get the one with patrimonio=2 in dadoscatalogo (which has "tons" in titulo), and the one with palchave=programming (which would have patrimonio=1) 当他们加入时,我希望它有4条记录,它将在dadoscatalogo中获得patrimonio = 2的记录(在titulo中具有“吨”),并且获得palchave = programming的记录(其具有patrimonio = 1) )

As per my understanding run below query: 根据我的理解运行以下查询:

 SELECT dadoscatalogo.patrimonio
FROM dadoscatalogo 
  INNER JOIN palavras_chave 
   ON dadoscatalogo.patrimonio=palavras_chave.patrimonio 
WHERE dadoscatalogo.titulo LIKE '%tons%' 
  OR palavras_chave.palchave LIKE '%programming%';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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