gpt4 book ai didi

mysql - 简单的 MySQL Join 来替换外键

转载 作者:行者123 更新时间:2023-11-29 08:50:49 24 4
gpt4 key购买 nike

我有 2 张 table 、门票和状态。票证有一个外键状态,对应于state.id

SELECT tickets.id AS 'Ticket Id', 
state.description AS 'State'
FROM tickets
LEFT JOIN state ON tickets.state = state.id
WHERE tickets.id = 1;

因此,如果我的票证中有一行 Tickets.id = 1 且 Tickets.state = 1,并且状态中有一行 State.id = 1 且 state.description = 'Open'

如何获得结果 Ticket Id = 1,State = Open?

编辑:这确实有效,由于某种原因状态表是空的......

最佳答案

好像是这样

SELECT tickets.id AS 'Ticket Id', 
state.description AS 'State'
FROM tickets
LEFT JOIN state ON tickets.state = state.id
WHERE tickets.id = 1 and state.state = 'open';

关于mysql - 简单的 MySQL Join 来替换外键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11282403/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com