简体   繁体   English

如何从另一个表中没有特定值的UID的表中选择*?

[英]How can I select * from a table where a UID doesn't exist with a certain value in another table?

I have two tables and what I'm trying to acheive is to grab a PhotoEmbed code from the Photos table so I can then use it to display a photo on the webpage - Each time the webpage is reloaded it will show a new picture. 我有two表,而我想要达到的目的是从“ Photos表中获取一个PhotoEmbed代码,这样我就可以用它在网页上显示照片-每次重新加载网页时,它都会显示一张新照片。 But I don't want to keep displaying the same picture?! 但是我不想一直显示相同的图片吗? I want to display a new picture each time...So I've set up the following tables but Have no idea how to run a query to actually grab the SELECT PhotoEmbed FROM Photos WHERE **CURRENT UserID** FROM Seen WHERE Seen **IS NOT EQUAL TO 1** 我想每次显示一张新图片...所以我建立了以下表格,但不知道如何运行查询以实际获取SELECT PhotoEmbed FROM Photos WHERE **CURRENT UserID** FROM Seen WHERE Seen **IS NOT EQUAL TO 1**

If the Seen is equal to 1 then run the query again and find a new PhotoEmbed code. 如果Seen等于1则再次运行查询并找到新的PhotoEmbed代码。 Would you do this with a query or just select * from Photos and all from Seen and then USE PHP to determine what embed code to use? 您将使用查询来执行此操作,还是仅从select * from Photos and all from Seen ,然后select * from Photos and all from Seen ,然后使用PHP确定要使用的嵌入代码?

Below Is a demo of two database tables. 下面是两个数据库表的演示。 On the left there is the Photos Table and on the right (starting at userID) there is the Seen table. 左侧是Photos Table ,右侧(从userID开始)是Seen表。

| PhotoID | PhotoEmbed|    |UserID    | PhotoID |Seen |

| 1       |Filename.jpg|   |2         | 1       |1    |

Get all photos which are not in the seen table like this: 像这样获取所有不在可见表中的照片:

SELECT PhotoID,etc from Photos where PhotoID NOT IN (select PhotoID from Seen where UserId = 1)

Given if you insert only viewed images in Seen table ( seen column,which I guess is bool could be removed), if you insert a new image I don't suppose for each user you should populate the table with seen set to 0. 如果插入只有看的图像由于 Seen表( seen列,我猜是bool可以被删除),如果插入一个新的形象我不认为每个用户,你应该填充表seen设置为0。

If by any chance the user saw all images consider making a random fetch: 如果有机会用户看到了所有图像,请考虑进行随机获取:

SELECT * FROM PhotosORDER BY RAND() LIMIT 1;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在表中选择一个值,如果它不存在另一个值? - How to select a value in a table and if it doesn't exist another value? 从没有在另一个表中出现的表中选择PHP - Select from table where doesn't appear in another table PHP 如何设置表中的一列,而另一表中的列具有特定值? - How can I set one column in a table where a column in another table has a certain value? Laravel - 从一个表中获取记录,该记录在另一个表中不存在,并附有 where 子句 - Laravel - Get records from one table that doesn't exist in another with a where clause attached 从表A和B中选择,其中表A和表B中的记录在表C中不存在? - Select from table A and B, where records from table A and table B don't exist in table C? SQL如何从另一个表中不存在的表中选择 - Sql how to select from a table that does not exist in another table 如何使用PHP查询MySQL的某些行,然后针对每一行,基于一个UID,基于值查询另一个表? - How to use PHP to query MySQL for certain rows, then for each row, based on a UID, query another table based on value? 当我选择一个不存在的表时,PDO没有捕获错误 - PDO not catching error when I SELECT a table that doesn't exist 如何使用WHERE和AND根据另一个特定值从表中提取特定值? - How can I pull specific value from my table using WHERE and AND based on another specific value? WordPress和SQL-如果列值不存在,则从另一个表更新和插入 - WordPress and SQL - Update and Insert from another table if column value doesn't exist
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM