从mysql中的许多表中获取结果

发布于 2024-12-10 00:11:01 字数 270 浏览 0 评论 0原文

我有几个表,我需要从一个查询中获取结果。

这就是我今天的做法。

$sql="select * from structure 
a, audio b where a.id=b.id_parent and b.published=1 order by b.data desc";

这给了我一个音频列表。 我需要做的是从许多表中获取响应。正如你所看到的,我正在调用两个表结构和音频。我需要从结构、音频、矢量和照片中获得结果。有什么线索我会怎么做吗?

I have a few tables wich I need to get results from into one query.

This is how I make it today.

$sql="select * from structure 
a, audio b where a.id=b.id_parent and b.published=1 order by b.data desc";

This gives me a list of audio.
What I need to do is get responses from many tables. As you can see I am calling two tables structure and audio. I need to get results from structure, audio, vector and photos. Any clues how I would do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我的奇迹 2024-12-17 00:11:01

如果这些表中有关系,那么您可以使用联接从多个表编辑中获取数据,

select * from structure 
a inner join 
audio b on a.id=b.id_parent where b.published=1 order by b.data desc

根据用户的评论,

您可以进行嵌套例如内连接

    SELECT DISTINCTROW 
       tblChippingSystems.Manufacturer_ID
     , tblChippingSystems.Chippingcounter
     , tblManufacturer.ManufacturerDesc
     , tblChippingSystems.Customer_ID 
  FROM ( tblChippingSystems 
INNER
  JOIN tblManufacturer 
    ON tblChippingSystems.Manufacturer_ID 
     = tblManufacturer.Manufacturer_ID )
INNER
  JOIN tblModel 
    ON tblChippingSystems.Model_ID = tblModel.Model_ID
 WHERE tblChippingSystems.Customer_ID =   k
ORDER 
    BY tblChippingSystems.Manufacturer_ID DESC

但请确保您在这些表格之间有正确的参考
仔细检查您的结果数据

if you have relationship in those tables then you can use joins to get data from multiple table

select * from structure 
a inner join 
audio b on a.id=b.id_parent where b.published=1 order by b.data desc

edited as per comment from user

you can do nesting of inner join for example

    SELECT DISTINCTROW 
       tblChippingSystems.Manufacturer_ID
     , tblChippingSystems.Chippingcounter
     , tblManufacturer.ManufacturerDesc
     , tblChippingSystems.Customer_ID 
  FROM ( tblChippingSystems 
INNER
  JOIN tblManufacturer 
    ON tblChippingSystems.Manufacturer_ID 
     = tblManufacturer.Manufacturer_ID )
INNER
  JOIN tblModel 
    ON tblChippingSystems.Model_ID = tblModel.Model_ID
 WHERE tblChippingSystems.Customer_ID =   k
ORDER 
    BY tblChippingSystems.Manufacturer_ID DESC

but make sure that you have proper reference between these tables and
double check your resulted data

凝望流年 2024-12-17 00:11:01

另一种方法是在数据库中创建基于连接查询的视图。这样,您的程序只需要知道从该视图进行查询即可。

您仍然需要编写连接 SQL,但至少在完成之后,它将对其余编码透明。

Another way would be to create a view in the database that is based on the joined query. That way, your program just need to knwo to query from that view.

You will still need to writ the join SQL, but at least after it is done, it will be transparent to the rest of the coding.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文