
参考语句:
内连接
select from student a
inner join stuMarks b
on astuid=bstuid
外连接
select from student a
inner join stuMarks b
on astuid=bstuid
交叉连接
select from student a
crossjoin stuMarks badoquery1close;
adoquery1sqlclear;
adoquery1sqltext:='select aproductname from products as a join categoerys as b on aproductid=bproductid';
adoquery1open;
这样的话你就可以使用ADOQUERY中的数据了,比如加到datasource中,然后dbgrid控件的dataset=datasource1,datasource1dataset=adoquery1;
两个表关联是使用ADOQUERY的sql语句关联点击Access的"工具"/"关系",
会d出一个"显示表"的窗口
点击"两者都有"属性页,
选择要关联的表,点"添加"按钮,
所选择的表就会出现在背后的体中,
选择完成后,点击"关闭"按钮
下一步就是建立关联:
将要确定关系的一个表(叫表A)的字段拖到另一相关的表的相应字段,
就会d出一个叫"编辑关系"的窗口,
点击"创建"按钮就OK了
(至于创建类型等,一般不用更改,但具体看你的需要了)
删除关联只要点下两表中的线,右击删除就OK!!!!
mysql支持多个库中不同表的关联查询,你可以随便链接一个数据库
然后,sql语句为:
select from db1table1 left join db2table2 on db1table1id = db2table2id
只要用数据库名加上""就能调用相应数据库的数据表了
数据库名表名
扩展资料mysql查询语句
1、查询一张表: select from 表名;
2、查询指定字段:select 字段1,字段2,字段3from 表名;
3、where条件查询:select 字段1,字段2,字段3 frome 表名 where 条件表达式;
例:select from t_studect where id=1;
select from t_student where age>22
4、带in关键字查询:select 字段1,字段2 frome 表名 where 字段 [not]in(元素1,元素2);
例:select from t_student where age in (21,23);
select from t_student where age not in (21,23);
5、带between and的范围查询:select 字段1,字段2 frome 表名 where 字段 [not]between 取值1 and 取值2;
例:select frome t_student where age between 21 and 29;
select frome t_student where age not between 21 and 29;
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)