从mysql中的许多表中获取结果
我有几个表,我需要从一个查询中获取结果。
这就是我今天的做法。
$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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果这些表中有关系,那么您可以使用联接从多个表编辑中获取数据,
根据用户的评论,
您可以进行嵌套例如内连接
if you have relationship in those tables then you can use joins to get data from multiple table
edited as per comment from user
you can do nesting of inner join for example
另一种方法是在数据库中创建基于连接查询的视图。这样,您的程序只需要知道从该视图进行查询即可。
您仍然需要编写连接 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.