Mysql sql如何使用select查询获取调用外键

Mysql sql如何使用select查询获取调用外键,mysql,Mysql,我想知道如何使用select查询来检索列表的所有报价 任何提示或帮助,以改善我的代码感谢!谢谢你,祝你今天愉快 CREATE DATABASE IF NOT EXISTS `assignment_db`; USE `assignment_db`; CREATE TABLE USER_LIST( id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, userName VARCHAR(50) NOT NULL, email varchar(100) NOT

我想知道如何使用select查询来检索列表的所有报价

任何提示或帮助,以改善我的代码感谢!谢谢你,祝你今天愉快

CREATE DATABASE  IF NOT EXISTS `assignment_db`;
USE `assignment_db`;

CREATE TABLE USER_LIST(
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
userName VARCHAR(50) NOT NULL,
email varchar(100) NOT NULL,
registeredDate timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
);


create table listing_list(
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
itemName VARCHAR(50) NOT NULL,
itemDescription VARCHAR(254) NOT NULL,
price DECIMAL(4,2) NOT NULL,
fk_poster_id int references USER_LIST(id),
created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
);

create table offer_list(
id int(6) Unsigned auto_increment Primary key,
offer int,
fk_listing_id int references listing_list(id),
fk_offeror_id int references user_list(id),
created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
);

insert into user_list (userName, email) values ('John','johnnyboi@123.com');
insert into user_list (userName, email) values ('Tom','Tommyboi@123.com');
insert into listing_list (itemName,itemDescription, price) values ( 'Pen', 'A long delicate pen.',' 1.50 ');
insert into listing_list (itemName,itemDescription, price) values ( 'Pencil', 'A long delicate pencil.',' 0.50 ');
insert into offer_list (offer,fk_listing_id,fk_offeror_id) values ('200','2','3');
insert into offer_list (offer,fk_listing_id,fk_offeror_id) values ('200','1','1');

现有用户的所有优惠列表:

select a.*,b.*,c.* from offer_list a
INNER JOIN (listing_list as b)
on a.fk_listing_id=b.Id

INNER JOIN (user_list as c)
on a.fk_offeror_id=c.Id
只需所有报价列表

select a.*,b.* from listing_list b
INNER JOIN (offer_list as a)
on a.fk_listing_id=b.Id
只需所有优惠都以第二种方式上市

select a.*,b.* from offer_list a
 INNER JOIN (listing_list as b)
on a.fk_listing_id=b.Id

检查这里,我在这个

中测试了它们,而这个fk_listing_id int引用了listing_list(id),如果也没有生成fk,则不会导致语法错误(至少在我的版本中不会)。是否在您的中(显示创建表)