联接3个三桌 [英] Joining 3 three tables

查看:96
本文介绍了联接3个三桌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这张图可以解释我的情况,在连接3个表时我需要一些帮助,但我不知道该怎么做:

I have this diagram which should explain my situation I need some help on joining 3 tables which I have no idea how to do this kind of thing:

因此,我可以执行以下操作来检索记录的循环:

So I can go through a while loop of retrieving the records by doing this:

<img src="<?php echo $row['filename']; ?>" alt="" />

Album: <?php echo $row['album_name']; ?> 
AlbumID: <?php echo $row['album_id']; ?>

推荐答案

使用 INNER JOIN 将阻止返回没有图像的相册. ORDER BY ... DESC 会将结果按降序排序确定如何只返回最后一条记录.它需要某种ORDER BY, GROUP BY 顶部.

Using an INNER JOIN will prevent returning albums that don't have images. The ORDER BY ... DESC will sort the results in descending order but I'm not sure how to only return the last record. It would take some sort of combination of ORDER BY, GROUP BY and TOP, perhaps.

SELECT 
    album_table.album_id, 
    album_table.album_name, 
    images_table.filename
FROM album_table
INNER JOIN images_table ON images_table.album_id = album_table.album_id
WHERE album_table.user_id = uid
ORDER BY images_table.date DESC

这篇关于联接3个三桌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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