简体   繁体   English

选择在a列中找到b列的行

[英]Select rows where column b is found in column a

I have a table that looks like this... 我有一张看起来像这样的桌子...

------------------------------------
| sku            | superseded_sku  |
------------------------------------
| PartA          | PartC           |
| PartB          | PartC           |
| PartC          | PartD           |
| PartD          |                 |

I need to write a query that will show me all rows where an entry from coumn B appears in column A. For example here it would give me the following... 我需要编写一个查询,向我显示列A中列B条目出现的所有行。例如,在这里它将给我以下内容...

------------------------------------
| sku            | superseded_sku  |
------------------------------------
| PartC          | PartD           |
| PartD          |                 |

I have tried this... 我已经尝试过了...

SELECT x.sku, x.superseded_sku FROM table x
JOIN table y ON y.sku = x.sku
WHERE y.superseded_sku = x.sku

but it returns nothing and now I don't know where to go from here 但它什么也没返回,现在我不知道从这里去哪里

Think this query will give you the result: 认为此查询将为您提供结果:

SELECT x.sku, x.superseded_sku FROM table x
JOIN table y ON y.sku = x.superseded_sku  

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

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