关系数据库简单搜索字符串

发布于 2024-10-18 15:35:02 字数 875 浏览 3 评论 0原文

嘿伙计们, 这是我之前提出的问题的后续。这是我第一次使用关系数据库,我需要快速搜索字符串的帮助来得出所需的结果。

背景信息:我正在为我的照片组合创建一个数据库,并希望能够通过其类别检索图像链接/数据。每个图像可以在多个类别中列出。

我的数据库设置如下:

tbl_imagesimage_idimage_titleimage_locationimage_descripimage_url

tbl_categoriescategory_idcategory_namecategory_descrip )

TABLE tbl_image_categories (image_id,category_id)

其中我的一张图像 (image_id=1) 有两个类别(沙漠 [category_id=1] 和冬天 [category_id=2])。我在 tbl_image_categories 中将其定义为 1,1 和 1,2。

我还有一些其他图像被定义为沙漠图像 [category_id=1]。

我将如何根据沙漠类别获取应加载的图像?

我试过:

SELECT tbl_images.image_url
FROM tbl_images,
tbl_image_categories,
tbl_categories
WHERE tbl_categories.category_id = 1

Hey guys,
This is a follow-up to a question that I asked earlier. It is my first time using a relational database and I need help with a quick search string to bring up desired results.

Background information: I'm making a database for my photo portfolio and want to be able to retrieve image links/data via their categories. Each image can be listed in multiple categories.

My database is set-up as follows :

TABLE tbl_images (image_id, image_title, image_location, image_descrip,image_url)

TABLE tbl_categories (category_id,category_name,category_descrip)

TABLE tbl_image_categories (image_id,category_id)

Where one of my images (image_id=1) has two categories (Desert [category_id=1] and Winter [category_id=2]). Which I defined in tbl_image_categories as 1,1 and 1,2.

I also have a few other images that I defined as Desert images [category_id=1].

How would I go about getting which images should be loaded based on the Desert Category?

I tried:

SELECT tbl_images.image_url
FROM tbl_images,
tbl_image_categories,
tbl_categories
WHERE tbl_categories.category_id = 1

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

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

发布评论

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

评论(1

挽清梦 2024-10-25 15:35:03

试试这个:

SELECT DISTINCT tbl_images.image_url
FROM tbl_images,
tbl_image_categories,
tbl_categories
WHERE chad_categories.category_id = 1 //category_id=1 for Desert
AND chad_images.image_id = chad_image_categories.image_id
AND chad_image_categories.category_id = chad_categories.category_id

Try this:

SELECT DISTINCT tbl_images.image_url
FROM tbl_images,
tbl_image_categories,
tbl_categories
WHERE chad_categories.category_id = 1 //category_id=1 for Desert
AND chad_images.image_id = chad_image_categories.image_id
AND chad_image_categories.category_id = chad_categories.category_id
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文