对两表进行关联信息SQL查询语句?

情况距离如下:
table1 中存在字段card、id、time
table2 中存在字段id、plan
现我有card字段的单个信息,想通过一个语句直接做到通过table1查询到id后直接关联查询表2得出plan字段结果信息,请问语句怎么写

table1和table2 是否有主外键关系?假设table1中的id 为table2中的外键,可以这样写 select plan from table2 where id =(select id form table1 where card =")追问

再额外问下,如果两个表在两个数据库里,那么这个语句还适用吗,还是需要做什么修改;不知道是不是你说的主外键的关系那个问题

温馨提示:答案为网友推荐,仅供参考
第1个回答  2019-11-19
select table2.plan from table1 inner join table2 on table1.id = table2.id where table1.card = 已知的card字段值本回答被网友采纳
第2个回答  2019-11-19
select * from table1 join table2 on table1.id=table2.id where card="xxx";追问

为什么会提示
Duplicate column name 'id'

追答

*号代表所有,“Duplicate column name 'id'”提示你有两个ID字段,你把它替换成你想要的plan字段吧

第3个回答  2019-12-22
select plan from table2 where id= select id from table1 where card=‘’
相似回答