查询表单相关表 [英] Querying form related tables

查看:64
本文介绍了查询表单相关表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好
我有一个带有一些表的数据库.这些表中的每两个都关联在一起.我想问一下如何用一个查询在数据库中搜索,并用相同的查询在与它相关的另一张表的行中找到它的结果?

例如我有2个名为"table1"的表,其字段为:代码,日期,...''
还有一个名为"related-to-table1"的表,其字段为:"code,text,id,...".该表通过代码关联,并且在"table1"中,"code"是一个自动递增字段,但在"related-to-table1"中则不是,并且对于"table1"中的每个代码,可以有多个一个在另一个表中.

我想看看如何在"table1"中的特定日期之间搜索并从"related-to-table1"中选择每一行,其中"table1"中的代码具有我们想要的日期?

抱歉,很长的问题和我的英语!

Hi
I have an database with some tables in it. each two of the tables are related together. i want to ask how can i search in the database with one query and find the results of it with the rows of the other table that are related to it beside it with the same query?

for example i have 2 tables named "table1" with fields:''code, date, ...''
and a table called "related-to-table1" with fields:''code, text, id, ...''. The table''s are related by code and in "table1", "code" is an auto increment field but in "related-to-table1" it''s not and for each code in "table1" there could be more than one in the other table.

I want to see how can i search between a specific date in "table1" and select every row from the "related-to-table1" where its code in "table1" has the date we want?

sorry for the long question and my English!

thanks!

推荐答案

要检索两个表之间的数据,请在它们之间进行Join .
要了解有关SQL连接基础的更多信息,请访问 http://www.w3schools.com/sql/sql_join.asp [ ^ ].
To retrieve the data between two tables, you do Join between them.
To know more about basics of SQL joins, visit http://www.w3schools.com/sql/sql_join.asp[^].


在日期列上使用JoinWhere子句作为条件/过滤器.

使用联接

SQL WHERE子句
Using Join and Where clause for condition/filter on your Date-Column.

Using Joins

SQL WHERE Clause


这篇关于查询表单相关表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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