{"id":206,"date":"2018-08-25T19:33:06","date_gmt":"2018-08-25T11:33:06","guid":{"rendered":"https:\/\/www.ccagml.com\/?p=206"},"modified":"2018-11-27T17:37:40","modified_gmt":"2018-11-27T09:37:40","slug":"175-combine-two-tables","status":"publish","type":"post","link":"https:\/\/www.ccagml.com\/?p=206","title":{"rendered":"175. Combine Two Tables"},"content":{"rendered":"<div class=\"sql-schema-wrapper__2C7v\"><a class=\"sql-schema-link__1HYH\">SQL Schema<\/a><\/div>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\"> \r\nCreate table Person (PersonId int, FirstName varchar(255), LastName varchar(255))\r\nCreate table Address (AddressId int, PersonId int, City varchar(255), State varchar(255))\r\nTruncate table Person\r\ninsert into Person (PersonId, LastName, FirstName) values ('1', 'Wang', 'Allen')\r\nTruncate table Address\r\ninsert into Address (AddressId, PersonId, City, State) values ('1', '2', 'New York City', 'New York')\r\n<\/pre>\n<div>\n<p>Table:\u00a0<code>Person<\/code><\/p>\n<pre>+-------------+---------+\r\n| Column Name | Type    |\r\n+-------------+---------+\r\n| PersonId    | int     |\r\n| FirstName   | varchar |\r\n| LastName    | varchar |\r\n+-------------+---------+\r\nPersonId is the primary key column for this table.\r\n<\/pre>\n<p>Table:\u00a0<code>Address<\/code><\/p>\n<pre>+-------------+---------+\r\n| Column Name | Type    |\r\n+-------------+---------+\r\n| AddressId   | int     |\r\n| PersonId    | int     |\r\n| City        | varchar |\r\n| State       | varchar |\r\n+-------------+---------+\r\nAddressId is the primary key column for this table.\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>Write a SQL query for a report that provides the following information for each person in the Person table, regardless if there is an address for each of those people:<\/p>\n<pre>FirstName, LastName, City, State<\/pre>\n<\/div>\n<p><strong>Mysql<\/strong><\/p>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\"> \r\n\r\nselect FirstName, LastName, City, State from Person left join Address on Person.PersonId = Address.PersonId\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>SQL Schema Table:\u00a0Person +&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;+ | Co<a href=\"https:\/\/www.ccagml.com\/?p=206\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">175. Combine Two Tables<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[29,20],"tags":[],"_links":{"self":[{"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/posts\/206"}],"collection":[{"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=206"}],"version-history":[{"count":2,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/posts\/206\/revisions"}],"predecessor-version":[{"id":208,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/posts\/206\/revisions\/208"}],"wp:attachment":[{"href":"https:\/\/www.ccagml.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=206"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=206"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=206"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}