摆脱两列选择中的一列重复值 [英] Get rid from one column duplicate values in two column select

查看:84
本文介绍了摆脱两列选择中的一列重复值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我有两列t1.NAME和t2.ITEMS,对于每个neme都可以分配一个以上的项目,所以我想选择它:

So, I`ve got two columns t1.NAME and t2.ITEMS, for each neme there can be more than one item assigned to it, so I want to select it like:

| NAME | ITEMS |
  JOHN    1
          2
  BEN     4
          7
          3
  DAVE    5

P.s.如果有帮助,它们之间通过t1.id = t2.names_id

P.s. if it helps, they are connected by t1.id = t2.names_id

推荐答案

我的以下查询的结果非常接近您想要的结果.唯一的区别是,没有空白名称,因为您不能直接执行该操作一步查询..每个项目都属于t1中每个id的名称.但是,如果要获得准确的结果,可以在此处进行一些技巧,可以使用UPDATE对结果进行一些技巧.

Result of my below query is very close to what you want.. the only difference is, there is no blank name, because you cannot directly do that result in one step query.. each item belong to name of each id in t1. BUT you can do some trick there if you want to get the exact result, you can use UPDATE to do some trick with the result.

    SELECT t1.NAME, t2.ITEMS
    FROM t1 INNER JOIN t2 ON t1.id = t2.names_id

这篇关于摆脱两列选择中的一列重复值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆