gpt4 book ai didi

MySQL查询返回带有详细/重复信息的数据

转载 作者:行者123 更新时间:2023-11-29 07:58:20 26 4
gpt4 key购买 nike

我正在处理MySQL数据库,我需要用程序选择一些数据。所以我有类似的东西:

CREATE TABLE pet (id INT, name VARCHAR(20), own_id INT);
insert into pet values (1,"Rufus", 1);
insert into pet values (2,"Bali", 1);
insert into pet values (3,"Lolo", 2);

ref pet.own_id = own.id

CREATE TABLE own (id INT, own_name VARCHAR(20), own_color VARCHAR(20));
insert into own values (1,"Me", "Red");
insert into own values (2,"Other" ,"Green");

现在我想知道如何选择/连接数据以获得类似的结果(作为结果):

own_name    own_color   name
Me Red Rufus
Me Red Bali
Other Green Lolo

最佳答案

SELECT own_name, own_color, name
from pet
JOIN own on (pet.own_id = own.id)
;

关于MySQL查询返回带有详细/重复信息的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24532118/

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