简体   繁体   English

尝试使用where子句从两个不同的表中提取时出现MySQL查询错误

[英]Mysql query error when trying to extract from two different tables with where clause

I am not able to retrieve query result when I am trying to extract data from two different table where column data matches(b/w column of first table and column of second table) 当我尝试从列数据匹配的两个不同表中提取数据时,我无法检索查询结果(第一个表的黑白列和第二个表的列)

I used following 2 methods: 我使用以下2种方法:

 SELECT a.*, FROM `table1` a, `table2` b
 WHERE a.`synonyms` in (b.`synonyms`);

or 要么

SELECT a.*, FROM `table1` a, `table2` b
WHERE a.`synonyms`=b.`synonyms`;

and

SELECT * FROM `table1` where `synonyms` in (SELECT `synonyms`from `table2`WHERE 1);

First Query showing error: 显示错误的第一个查询:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM `table1` a, `table2` b  WHERE' at line 1

Second query is running long time and then at the end displaying nothing except: show your query. 第二个查询运行时间很长,最后没有显示任何内容,除了:显示查询。

What mistake am I making here? 我在这里犯什么错误?

PS: tabel1 and table both having synonyms column (value of synonym is in varchar). PS:tabel1和表都具有同义词列(同义词的值在varchar中)。 around 300k synonyms(eg:gene name) are there in table1. table1中大约有30万个同义词(例如:基因名称)。 table2 have around 5000 synonyms which also exsist in table1. table2具有大约5000个同义词,它们也存在于table1中。 I want to extract those 5000 from table1 with extra information it contain. 我想从table1中提取其中包含的5000条信息。

    SELECT * FROM `table1` where `synonyms` in ('synonym1','synonym2','synonym3','synonym4'); 

SELECT a.*, FROM更改为SELECT a.* FROM

In the second query you should define WHERE... = 'something'. 在第二个查询中,您应该定义WHERE ... ='something'。

The right syntax is WHERE column_name operator value; 正确的语法是WHERE column_name运算符值;

In first query you should remove comma like pointed already. 在第一个查询中,您应该删除已经指向的逗号。

Change 更改

 SELECT a.*, FROM

to

SELECT a.* FROM

plus use join in your query like 加上在查询中使用join

SELECT a.* FROM `table1` a join `table2` b on (a.synonyms=b.synonyms);

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

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