Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 从两个表中检索数据。_Sql_Select - Fatal编程技术网

Sql 从两个表中检索数据。

Sql 从两个表中检索数据。,sql,select,Sql,Select,我有两(2)个表,用户和警告 在用户中,我有三(3)列:uid、rank和语言 在警告中,我还有三(3)列:id,警告,和警告处于活动状态 所以我的问题是:如何在phpmyadmin中显示所有结果,其中: 排名='2' 语言='en' warn\u active=“是” 在这两个表中,uid/id代表用户唯一的id 提前感谢您的帮助 试试这个 Select u.*,w.* from users u inner join warnings w on u.uid == w.id where

我有两(2)个表,
用户
警告

用户
中,我有三(3)列:
uid
rank
语言

警告
中,我还有三(3)列:
id
警告
,和
警告处于活动状态

所以我的问题是:如何在phpmyadmin中显示所有结果,其中:

  • 排名
    ='2'
  • 语言
    ='en'
  • warn\u active
    =“是”
在这两个表中,
uid
/
id
代表用户唯一的id

提前感谢您的帮助

试试这个

Select u.*,w.* from users u inner join warnings w on u.uid == w.id 
 where u.rank=2 and u.language='en' and w.warn_active='yes'
试试这个

Select u.*,w.* from users u inner join warnings w on u.uid == w.id 
 where u.rank=2 and u.language='en' and w.warn_active='yes'

这两张桌子之间有什么关系? 如果你有多对多。。然后创建第三个表,如下所示

create table user_warnings(uid integer REFERENCES users(uid),id integer REFERENCES warnings(id));
在表中插入ID值用户\每个表中相互关联的两个ID的警告 然后触发下面的查询

Select * from users,warnings,users_warnings where users.uid=users_warnings.uid and warnings.id=users_warnings.id and users.rank=2 and users.language='en' and warnings.warn_active='yes';

如果您遇到任何错误,请告诉我。

这两个表之间有什么关系?
Select u.uid,u.rank,u.language, w.warnings  from users u inner join warnings w on u.uid == w.id 
 where u.rank=2 and u.language='en' and w.warn_active='yes'
如果你有多对多。。然后创建第三个表,如下所示

create table user_warnings(uid integer REFERENCES users(uid),id integer REFERENCES warnings(id));
在表中插入ID值用户\每个表中相互关联的两个ID的警告 然后触发下面的查询

Select * from users,warnings,users_warnings where users.uid=users_warnings.uid and warnings.id=users_warnings.id and users.rank=2 and users.language='en' and warnings.warn_active='yes';

如果您遇到任何错误,请告诉我。

这是家庭作业吗?你试过什么?向我们展示一些可以帮助您的东西。:-)一个简单的内部连接,有3个条件。这是我的网站,我用phpmyadmin浏览表格。这是家庭作业吗?你试过什么?向我们展示一些可以帮助您的东西。:-)一个简单的内部连接有3个条件。这是我的网站和im使用phpmyadmin浏览表。
Select u.uid,u.rank,u.language, w.warnings  from users u inner join warnings w on u.uid == w.id 
 where u.rank=2 and u.language='en' and w.warn_active='yes'