Sql 从两个表中检索数据。
我有两(2)个表,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
用户
和警告
在用户
中,我有三(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'