惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Simon Willison's Weblog
Simon Willison's Weblog
G
Google Developers Blog
Spread Privacy
Spread Privacy
I
InfoQ
V
V2EX
S
Schneier on Security
小众软件
小众软件
C
CERT Recently Published Vulnerability Notes
博客园 - 聂微东
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Stack Overflow Blog
Stack Overflow Blog
T
Threat Research - Cisco Blogs
L
Lohrmann on Cybersecurity
Recent Announcements
Recent Announcements
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Attack and Defense Labs
Attack and Defense Labs
云风的 BLOG
云风的 BLOG
The Hacker News
The Hacker News
S
SegmentFault 最新的问题
C
Cybersecurity and Infrastructure Security Agency CISA
NISL@THU
NISL@THU
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
GbyAI
GbyAI
Latest news
Latest news
S
Secure Thoughts
Project Zero
Project Zero
MongoDB | Blog
MongoDB | Blog
I
Intezer
Security Latest
Security Latest
Apple Machine Learning Research
Apple Machine Learning Research
Vercel News
Vercel News
N
Netflix TechBlog - Medium
V2EX - 技术
V2EX - 技术
量子位
T
Threatpost
T
The Blog of Author Tim Ferriss
Y
Y Combinator Blog
T
Tor Project blog
A
Arctic Wolf
Microsoft Security Blog
Microsoft Security Blog
T
The Exploit Database - CXSecurity.com
大猫的无限游戏
大猫的无限游戏
T
Tailwind CSS Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
C
Check Point Blog
博客园 - Franky
Google DeepMind News
Google DeepMind News
The Register - Security
The Register - Security
The GitHub Blog
The GitHub Blog
L
LINUX DO - 热门话题

博客园 - 00654

阳光已经好久不见 我这里有漂亮的繁体字,非主流图片 编写第一个JavaScript程序 - 00654 - 博客园 sql语句实现模糊搜索 反回上一页并刷新! - 00654 - 博客园 自己写的一个分页代码。写得不好哈! 取得页面执行时间的代码 - 00654 - 博客园 Java脚本提示用户是否确定操作。否则取消当前操作。 - 00654 - 博客园 checkbox控件.全选与不全选的切换 - 00654 - 博客园 用JavaScript判断用户输入的数据是否如何要求! - 00654 - 博客园 用Forms做管理员登陆。。。 [asp.net]Forms验证初步 SQL SERVER 函数 Scott Mitchell的ASP.NET2.0数据指南中文版索引 (好教程) Asp.Net 函数,方法。不断添加中。。 ASP.Net中控件的EnableViewState属性 ObjectDataSource控件的使用... Sql存储过程和函数集合.(不断更新中....) DateReader,DateAdapter,DateSet和SqlCommand的基本使用方法
Select嵌套查询.(子查询取得其他表字段的值.并显示在本次查询的结果)
00654 · 2006-12-03 · via 博客园 - 00654
全完是我个人理解.可能语言上有有错误....我也是才学SQL...

1SELECT ProductID, ProductName, SupplierID, CategoryID, QuantityPerUnit, UnitPrice, UnitsInStock, UnitsOnOrder, ReorderLevel, Discontinued,
2(SELECT CategoryName FROM Categories WHERE Categories.CategoryID = Products.CategoryID) as CategoryName
3 
FROM Products

查询Produces表原始数据...但是需要得出品种名称..表中CategoryID字段所记录的数据是品种的编号..
那么要通过品种编号ID得出品种名称.所以在主查询设置所需要查询字段的部分`加入子查询

SELECT CategoryName FROM Categories WHERE Categories.CategoryID = Products.CategoryID

程序在执行查询过程中.就会执行这个子查询`找到符合条件的数据..然后得到一个返回数据.使用AS把数据放到子定义表CategoryName中.
最后得出结果就会多出一个CategoryName表.`里面装的数据就是当前本条记录的产品品种名称.

完整的例子:

1SELECT     ProductID, ProductName, SupplierID, CategoryID,
2QuantityPerUnit, UnitPrice, UnitsInStock, UnitsOnOrder, ReorderLevel, Discontinued,
3(SELECT CategoryName FROM Categories
4WHERE Categories.CategoryID = Products.CategoryID) as CategoryName,
5(SELECT CompanyName FROM Suppliers
6WHERE Suppliers.SupplierID = Products.SupplierID) as SupplierName
7FROM         Products
8
9