php - 类似于 MySQL 中的符号链接(symbolic link)的东西?

标签 php mysql sql record

是否可以在记录中存储指向另一条记录的“链接”?例如:

table USERS
id    name    link
-------------------------------------------------------
1     user1   [link to record with id=4 in table info]

所以,在 PHP 中,我可以这样做:

// connect to the database etc....
$query          = "select * from users where id=1";
$result         = mysql_query($query);
$another_result = mysql_result($result, 0, 'link');

因此 $another_result 以与使用 mysql_query() 调用时相同的原始格式存储另一个查询的结果。

这可能吗?

最佳答案

$query          = "select info.* from info 
                   inner join users on users.link = info.id 
                   where users.id=1";
$result         = mysql_query($query);

使用 JOIN 是 SQL 的基本组成部分,就像在 PHP 中使用 for 循环一样。

阅读A Visual Explanation of SQL Joins由无畏的领导者。

关于php - 类似于 MySQL 中的符号链接(symbolic link)的东西?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8621285/

相关文章:

php - 廉价的客户端识别和正确的 SSL 客户端身份验证

PHP/MySql 结合排序和分页

如果多行不匹配,Mysql 将默认值设置为 null

mysql - 使用 INNER JOIN 后搜索 SQL 查询

sql - 非常慢的查询内部连接

sql不同列比较

php - Windows MAMP - PHP CURL 问题

php - 使用 PHP 将 MySQL 查询输出为 SQLite

mysql - Liquibase 修改数据类型在 Mysql 上失败

c# - 为什么 MS Access 2007 不允许行插入,但在下一次插入尝试时允许它?