MySQL 表子查询
表子查询是指子查询返回的结果集是 N 行 N 列的一个表数据。
MySQL 表子查询实例
下面是用于例子的两张原始数据表:
article 表:
blog 表:
SQL 如下:
SELECT * FROM article WHERE (title,content,uid) IN (SELECT title,content,uid FROM blog)
查询返回结果如下所示:
该 SQL 的意义在于查找 article 表中指定的字段同时也存在于 blog
FROM 子查询
FROM 子句中的子查询
MySQL FROM 子查询是指 FROM 的子句作为子查询语句,主查询再到子查询结果中获取需要的数据。FROM 子查询语法如下:
SELECT ... FROM (subquery) AS name ...
子查询会生成一个临时表,由于 FROM 子句中的每个表必须有一个名称,因此 AS name 是必须的。FROM 子查询也称为衍生数据表子查询。
FROM 子查询实例
table1:
s1 s2
1 5
2 12
3 20
FRO
1、准备数据
以下操作将在该表中进行
create table student (
id int unsigned primary key auto_increment,
name char(12) not null,
gender enum("male","famale") default "male",
age tinyint unsigned not null,
hoc_group char(12) not null,
html tinyint unsigned not nu
程序代码: 代码如下: ‘关键字的搜索 str=”select * from tableName where id>4″ if srhKey”” then keyArr=split(srhKey,” “) j=UBound(keyArr) t=0 dim keystrArr() for i=0 to j if keyArr(i)”” then redim preserve keystrArr(t) strfilter=”(empZw like ‘%”&keyArr(i)&”%’ or e
程序代码: 以下为引用的内容: 代码如下:‘关键字的搜索 str=”select * from tableName where id>4″ if srhKey”” then keyArr=split(srhKey,” “) j=UBound(keyArr) t=0 dim keystrArr() for i=0 to j if keyArr(i)”” then redim preserve keystrArr(t) strfilter=”(empZw like ‘%”&keyArr(i)
代码如下: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Text.RegularExpressions; using System.IO; using System.Text; using System.Data; namespace SJ