是否可以检索一个对象,它只分成三个表,只有一个查询? [英] Is it possible to retrieve an object that is split into three tables with only one query?

查看:348
本文介绍了是否可以检索一个对象,它只分成三个表,只有一个查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

EDIT :答案有效,但很慢地减慢了查询速度。还有另一个解决方案吗?






我的程序中有以下对象。



拥有各种令牌的 TextBlock c>。



这三个数据库存储在数据库中,具有相同对象的namas的三个表。



我想知道是否可以只用一个查询来恢复程序中填充对象所需的所有数据。



我只需要一个查询,因为我使用 CURSOR 来遍历数据库中存储的所有对象。



数据库方案是: p>

页面(id,someAttributes)

TextBlock(id,pageId,someAttributes)

Token ,someAttributes)

解决方案

假设每一页都至少有一个Textblock,尝试

  SELECT * FROM 
页面P
INNER JOIN TextBlock T ON T.pageId = P. id
INNER JOIN Token TK ON TK.textblockId = T.id;

或者(旧语法):

  SELECT * FROM 
Page AS P,TextBlock T,Token TK WHERE
T.pageId = P.id AND
TK.textblockId = T.id;

如果上述条件可能不总是真的,那么您需要使用 OUTER JOIN 而不是 INNER JOIN


EDIT: The answers works, but slow down the query a lot. Is there another solution?


I have the following object in my program.

Page haves various TextBlock that haves various Token.

The three are stored in the database in three tables with the same namas of the objects.

I want to know if is possible to recover all the data needed to fill the object in the program with only one query.

I want only one query because I'm using a CURSOR to iterate over all the objects stored in the database.

The database scheme is this:

Page(id, someAttributes)
TextBlock(id,pageId, someAttributes)
Token(textblockId, someAttributes)

解决方案

Assuming that every Page has at least one Textblock with at least one Token each try

SELECT * FROM
Page AS P 
INNER JOIN TextBlock T ON T.pageId = P.id 
INNER JOIN Token TK ON TK.textblockId = T.id;

Alternatively (old syntax):

SELECT * FROM
Page AS P, TextBlock T, Token TK WHERE 
T.pageId = P.id AND
TK.textblockId = T.id;

IF it is possible that the above condition is not always true then you need to use OUTER JOIN instead of INNER JOIN.

这篇关于是否可以检索一个对象,它只分成三个表,只有一个查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆