组合两个表。请写出sql语句,执行结果是{“headers”: [“first_name”, “last_name”, “city”, “state”], “values”: [[“Allen”, “Wang”, null, null], [“Bob”, “Alice”, “New York City”, “New York”]]}。
两张表的sql语句如下:
DROP TABLE IF EXISTS `address`;
CREATE TABLE `address` (
`address_id` int(11) NOT NULL,
`person_id` int(11) NOT NULL,
`city` varchar(255) NOT NULL,
`state` varchar(255) NOT NULL,
PRIMARY KEY (`address_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
INSERT INTO `address` VALUES ('1', '2', 'New York City', 'New York');
INSERT INTO `address` VALUES ('2', '3', 'Leetcode', 'California');
DROP TABLE IF EXISTS `person`;
CREATE TABLE `person` (
`person_id` int(11) NOT NULL,
`first_name` varchar(255) NOT NULL,
`last_name` varchar(255) NOT NULL,
PRIMARY KEY (`person_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
INSERT INTO `person` VALUES ('1', 'Allen', 'Wang');
INSERT INTO `person` VALUES ('2', 'Bob', 'Alice');
sql语句如下:
select first_name, last_name, city, state
from person left join address
on person.person_id = address.person_id