来自两个表的数据,而不重复来自第一个表的数据? [英] Data from two tables without repeating data from the first?

查看:69
本文介绍了来自两个表的数据,而不重复来自第一个表的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MySQL数据库中有两个表.

I have two tables in a MySQL Database.

用户表和用户元表

我正在寻找一种通过一个查询从两个表中获取所有信息的方法.但无需重复用户"表中的信息.

I am looking for a way to get all the information out of both tables with one query. But without repeating the information from Users table.

这也是与用户ID号有关的所有信息.例如,user_id = 1.

This is all information relating to the users id number as well. So for example user_id = 1.

有没有一种方法可以查询数据库并从两个表中收集所有我的信息,而无需重复第一个表中的信息?

Is there a way to query the database and collect all the information I from both tables without repeating the information from the first?

结构示例

用户表

  • user_id
  • user_login
  • user_pass

用户元数据表

  • user_meta_id
  • user_id
  • user_meta_key
  • user_meta_value

我想摆脱这个问题

user_id, user_login, user_pass, user_meta_id, user_id, user_meta_key, user_meta_value
                                user_meta_id, user_id, user_meta_key, user_meta_value
                                user_meta_id, user_id, user_meta_key, user_meta_value

推荐答案

SELECT DISTINCT table1.id, table1.field2, table1.field3, tab_id.id_table1 
FROM table1 
LEFT JOIN tab_id ON (table1.id=tab_id.id_table1)

这篇关于来自两个表的数据,而不重复来自第一个表的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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