{"id":337,"date":"2024-11-26T11:38:31","date_gmt":"2024-11-26T04:38:31","guid":{"rendered":"https:\/\/www.pgtutorial.com\/?page_id=337"},"modified":"2025-02-10T14:58:57","modified_gmt":"2025-02-10T07:58:57","slug":"postgresql-cross-join","status":"publish","type":"page","link":"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-cross-join\/","title":{"rendered":"PostgreSQL Cross Join"},"content":{"rendered":"\r\n<p><strong>Summary<\/strong>: in this tutorial, you&#8217;ll learn how to use the PostgreSQL <code>CROSS JOIN<\/code> to merge rows from two tables.<\/p>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\" id='exploring-postgresql-cross-join-clause'>Exploring PostgreSQL Cross Join clause <a href=\"#exploring-postgresql-cross-join-clause\" class=\"anchor\" id=\"exploring-postgresql-cross-join-clause\" title=\"Anchor for Exploring PostgreSQL Cross Join clause\">#<\/a><\/h2>\r\n\r\n\r\n\r\n<p>The <code>CROSS JOIN<\/code> combines each row from the first table with every row from the second table and returns combinations of all rows.\u00a0\u00a0<\/p>\r\n\r\n\r\n\r\n<p>Unlike other joins like <a href=\"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-inner-join\/\">inner join<\/a>, <a href=\"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-left-join\/\">left join<\/a>, and <a href=\"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-full-join\/\">full join<\/a>, a cross join has no condition to match rows from the two tables.<\/p>\r\n\r\n\r\n\r\n<p>Here&#8217;s the syntax of the <code>CROSS JOIN<\/code> clause:<\/p>\r\n\r\n\r\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"><span class=\"hljs-keyword\">SELECT<\/span>\r\n  table1.column1,\r\n  table2.column2,\r\n  ...\r\n<span class=\"hljs-keyword\">FROM<\/span>\r\n  table1\r\n  <span class=\"hljs-keyword\">CROSS<\/span> <span class=\"hljs-keyword\">JOIN<\/span> table2;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\r\n\r\n\r\n<p>In this syntax:<\/p>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li>First, specify the name of the first table (<code>table1<\/code>) in the <code>FROM<\/code> clause.<\/li>\r\n\r\n\r\n\r\n<li>Second, provide the name of the second table (<code>table2<\/code>) in the <code>CROSS JOIN<\/code> clause.<\/li>\r\n\r\n\r\n\r\n<li>Third, list the columns from both tables that you want to retrieve data in the <code>SELECT<\/code> clause.<\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<p>If <code>table1<\/code> has <code>n<\/code> rows and <code>table2<\/code> has <code>m<\/code> rows, the <code>CROSS JOIN<\/code> will return a result set that has <code>nxm<\/code> rows.<\/p>\r\n\r\n\r\n\r\n<p>Alternatively, you can form a cross-join by listing two tables in the <code>FROM<\/code> clause, making the statement more concise but less obvious:<\/p>\r\n\r\n\r\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"><span class=\"hljs-keyword\">SELECT<\/span>\r\n  table1.column1,\r\n  table2.column2,\r\n  ...\r\n<span class=\"hljs-keyword\">FROM<\/span>\r\n  table1, table2;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\r\n\r\n\r\n<p>In practice, you use a cross-join when you want to have all possible combinations of rows from both tables.<\/p>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\" id='understanding-the-cross-join'>Understanding the cross join <a href=\"#understanding-the-cross-join\" class=\"anchor\" id=\"understanding-the-cross-join\" title=\"Anchor for Understanding the cross join\">#<\/a><\/h2>\r\n\r\n\r\n\r\n<p id=\"block-973a91d0-8e1f-4bc3-9f01-c5e188962280\">Suppose you want to join two tables <code>X<\/code> and <code>Y<\/code> using a cross join:<\/p>\r\n\r\n\r\n\r\n<ul id=\"block-1e3e94a1-323e-470b-a6d5-45d84dba0705\" class=\"wp-block-list\">\r\n<li>The <code>X<\/code> table has two columns <code>id <\/code>(key) and <code>x<\/code>.<\/li>\r\n\r\n\r\n\r\n<li>The <code>Y<\/code> table also has two columns <code>id<\/code> (key) and <code>y<\/code>.<\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-9d6595d7 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\"><div class=\"wp-block-image\">\r\n<figure class=\"alignright size-full\"><img decoding=\"async\" class=\"wp-image-1970\" src=\"https:\/\/www.pgtutorial.com\/wp-content\/uploads\/2025\/02\/x-table-cross-join.svg\" alt=\"\" \/><\/figure>\r\n<\/div><\/div>\r\n\r\n\r\n\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\"><div class=\"wp-block-image\">\r\n<figure class=\"alignleft size-full\"><img decoding=\"async\" class=\"wp-image-1971\" src=\"https:\/\/www.pgtutorial.com\/wp-content\/uploads\/2025\/02\/y-table-cross-join.svg\" alt=\"\" \/><\/figure>\r\n<\/div><\/div>\r\n<\/div>\r\n\r\n\r\n\r\n<p id=\"block-9b68ea9c-7eaa-4068-8a60-47d522b4824c\">The cross-join returns a result set that includes all possible combinations of rows from the left table with rows from the right table:<\/p>\r\n\r\n\r\n<div class=\"wp-block-image\">\r\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" class=\"wp-image-1969\" src=\"https:\/\/www.pgtutorial.com\/wp-content\/uploads\/2025\/02\/postgresql-cross-join-visualization.svg\" alt=\"PostgreSQL cross join visualization\" \/><\/figure>\r\n<\/div>\r\n\r\n\r\n<p>The following diagram is another way to depict a cross join:<\/p>\r\n\r\n\r\n<div class=\"wp-block-image\">\r\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" class=\"wp-image-1972\" src=\"https:\/\/www.pgtutorial.com\/wp-content\/uploads\/2025\/02\/postgresql-cross-join-diagram.svg\" alt=\"PostgreSQL cross join diagram\" \/><\/figure>\r\n<\/div>\r\n\r\n\r\n<h2 class=\"wp-block-heading\" id='setting-up-sample-tables'>Setting up sample tables <a href=\"#setting-up-sample-tables\" class=\"anchor\" id=\"setting-up-sample-tables\" title=\"Anchor for Setting up sample tables\">#<\/a><\/h2>\r\n\r\n\r\n\r\n<p>First, <a href=\"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-create-table\/\">create a new<\/a> table called <code>products<\/code>:<\/p>\r\n\r\n\r\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"><span class=\"hljs-keyword\">CREATE<\/span> <span class=\"hljs-keyword\">TABLE<\/span> products (\r\n  product_id <span class=\"hljs-type\">INT<\/span> <span class=\"hljs-keyword\">GENERATED<\/span> <span class=\"hljs-keyword\">ALWAYS<\/span> <span class=\"hljs-keyword\">AS<\/span> <span class=\"hljs-keyword\">IDENTITY<\/span> <span class=\"hljs-keyword\">PRIMARY KEY<\/span>,\r\n  <span class=\"hljs-type\">name<\/span> <span class=\"hljs-type\">VARCHAR<\/span>(<span class=\"hljs-number\">100<\/span>) <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-keyword\">NULL<\/span>,\r\n  price <span class=\"hljs-type\">DECIMAL<\/span>(<span class=\"hljs-number\">10<\/span>, <span class=\"hljs-number\">2<\/span>) <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-keyword\">NULL<\/span>\r\n);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\r\n\r\n\r\n<p>Second, <a href=\"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-insert\/\">insert three rows<\/a> into the <code>products<\/code> table:<\/p>\r\n\r\n\r\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"><span class=\"hljs-keyword\">INSERT<\/span> <span class=\"hljs-keyword\">INTO<\/span>\r\n  products (<span class=\"hljs-type\">name<\/span>, price)\r\n<span class=\"hljs-keyword\">VALUES<\/span>\r\n  (<span class=\"hljs-string\">'iPhone 14 Pro'<\/span>, <span class=\"hljs-number\">999.99<\/span>),\r\n  (<span class=\"hljs-string\">'iPhone 15 Pro'<\/span>, <span class=\"hljs-number\">1199.99<\/span>),\r\n  (<span class=\"hljs-string\">'Galaxy S23 Ultra'<\/span>, <span class=\"hljs-number\">1149.47<\/span>) \r\n<span class=\"hljs-keyword\">RETURNING<\/span> *;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\r\n\r\n\r\n<p>Output:<\/p>\r\n\r\n\r\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"plaintext\" data-shcb-language-slug=\"plaintext\"><span><code class=\"hljs language-plaintext\"> product_id |       name       |  price\r\n------------+------------------+---------\r\n          1 | iPhone 14 Pro    |  999.99\r\n          2 | iPhone 15 Pro    | 1199.99\r\n          3 | Galaxy S23 Ultra | 1149.47<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">plaintext<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">plaintext<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\r\n\r\n\r\n<p>Third, <a href=\"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-create-table\/\">create a new table<\/a> called <code>warehouses<\/code>:<\/p>\r\n\r\n\r\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"><span class=\"hljs-keyword\">CREATE<\/span> <span class=\"hljs-keyword\">TABLE<\/span> warehouses (\r\n  warehouse_id <span class=\"hljs-type\">INT<\/span> <span class=\"hljs-keyword\">GENERATED<\/span> <span class=\"hljs-keyword\">ALWAYS<\/span> <span class=\"hljs-keyword\">AS<\/span> <span class=\"hljs-keyword\">IDENTITY<\/span> <span class=\"hljs-keyword\">PRIMARY KEY<\/span>,\r\n  <span class=\"hljs-type\">name<\/span> <span class=\"hljs-type\">VARCHAR<\/span>(<span class=\"hljs-number\">100<\/span>) <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-keyword\">NULL<\/span>\r\n);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\r\n\r\n\r\n<p>Finally, <a href=\"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-insert\/\">insert two rows<\/a> into the <code>warehouses<\/code> table:<\/p>\r\n\r\n\r\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"><span class=\"hljs-keyword\">INSERT<\/span> <span class=\"hljs-keyword\">INTO<\/span>\r\n  warehouses(<span class=\"hljs-type\">name<\/span>)\r\n<span class=\"hljs-keyword\">VALUES<\/span>\r\n  (<span class=\"hljs-string\">'San Jose'<\/span>),\r\n  (<span class=\"hljs-string\">'San Francisco'<\/span>)\r\n<span class=\"hljs-keyword\">RETURNING<\/span> *;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\r\n\r\n\r\n<p>Output:<\/p>\r\n\r\n\r\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"plaintext\" data-shcb-language-slug=\"plaintext\"><span><code class=\"hljs language-plaintext\"> warehouse_id |     name\r\n--------------+---------------\r\n            1 | San Jose\r\n            2 | San Francisco<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">plaintext<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">plaintext<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\r\n\r\n\r\n<h2 class=\"wp-block-heading\" id='postgresql-cross-join-example'>PostgreSQL CROSS JOIN example <a href=\"#postgresql-cross-join-example\" class=\"anchor\" id=\"postgresql-cross-join-example\" title=\"Anchor for PostgreSQL CROSS JOIN example\">#<\/a><\/h2>\r\n\r\n\r\n\r\n<p>Suppose you must go to each warehouse and perform a physical inventory check. In this process, you must check the warehouse name, product, and quantity.<\/p>\r\n\r\n\r\n\r\n<p>You can produce a list that includes all possible combinations of warehouses and products before checking the inventory using a cross-join:<\/p>\r\n\r\n\r\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-9\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"><span class=\"hljs-keyword\">SELECT<\/span>\r\n  w.name warehouse_name,\r\n  p.name product_name,\r\n  <span class=\"hljs-string\">''<\/span> quantity \r\n<span class=\"hljs-keyword\">FROM<\/span>\r\n  products p\r\n  <span class=\"hljs-keyword\">CROSS<\/span> <span class=\"hljs-keyword\">JOIN<\/span> warehouses w;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-9\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\r\n\r\n\r\n<p><a href=\"https:\/\/www.pgtutorial.com\/playground\/?db=crossjoin&amp;q=U0VMRUNUIHcubmFtZSB3YXJlaG91c2VfbmFtZSwgcC5uYW1lIHByb2R1Y3RfbmFtZSwgJycgcXVhbnRpdHkgRlJPTSBwcm9kdWN0cyBwIENST1NTIEpPSU4gd2FyZWhvdXNlcyB3Ow\" target=\"_blank\" rel=\"noreferrer noopener\">Try it<\/a><\/p>\r\n\r\n\r\n\r\n<p>Output:<\/p>\r\n\r\n\r\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-10\" data-shcb-language-name=\"plaintext\" data-shcb-language-slug=\"plaintext\"><span><code class=\"hljs language-plaintext\"> warehouse_name |   product_name   | quantity\r\n----------------+------------------+----------\r\n San Jose       | iPhone 14 Pro    |\r\n San Jose       | iPhone 15 Pro    |\r\n San Jose       | Galaxy S23 Ultra |\r\n San Francisco  | iPhone 14 Pro    |\r\n San Francisco  | iPhone 15 Pro    |\r\n San Francisco  | Galaxy S23 Ultra |<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-10\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">plaintext<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">plaintext<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\r\n\r\n\r\n<p>The third column <code>quantity<\/code> is a blank for filling out the quantity of each product per warehouse.<\/p>\r\n\r\n\r\n\r\n<p>The following statement uses the alternative syntax of the cross-join to merge the rows from <code>products<\/code> and <code>warehouses<\/code> tables:<\/p>\r\n\r\n\r\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-11\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"><span class=\"hljs-keyword\">SELECT<\/span>\r\n  w.name warehouse_name,\r\n  p.name product_name,\r\n  <span class=\"hljs-string\">''<\/span> quantity \r\n<span class=\"hljs-keyword\">FROM<\/span>\r\n  products p, warehouses w;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-11\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\r\n\r\n\r\n<p><a href=\"https:\/\/www.pgtutorial.com\/playground\/?db=crossjoin&amp;q=U0VMRUNUIHcubmFtZSB3YXJlaG91c2VfbmFtZSwgcC5uYW1lIHByb2R1Y3RfbmFtZSwgJycgcXVhbnRpdHkgRlJPTSBwcm9kdWN0cyBwLCB3YXJlaG91c2VzIHc7\" target=\"_blank\" rel=\"noreferrer noopener\">Try it<\/a><\/p>\r\n\r\n\r\n\r\n<p>It returns the same output as the query above.<\/p>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\" id='summary'>Summary <a href=\"#summary\" class=\"anchor\" id=\"summary\" title=\"Anchor for Summary\">#<\/a><\/h2>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li>Use the <code>CROSS JOIN<\/code> to return all combinations of rows from two tables.<\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\" id='quiz'>Quiz <a href=\"#quiz\" class=\"anchor\" id=\"quiz\" title=\"Anchor for Quiz\">#<\/a><\/h2>\r\n\r\n\r\n\r\n<p><iframe loading=\"lazy\" class=\"iframe\" src=\"\/quiz\/?quiz=cross-join\" name=\"quiz\" width=\"600\" height=\"700\"><\/iframe><\/p>\r\n<div class=\"helpful-block-content\" data-title=\"\">\n\t<header>\n\t\t<div class=\"wth-question\">Was this tutorial helpful ?<\/div>\n\t\t<div class=\"wth-thumbs\">\n\t\t\t<button\n\t\t\t\tdata-post=\"337\"\n\t\t\t\tdata-post-url=\"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-cross-join\/\"\n\t\t\t\tdata-post-title=\"PostgreSQL Cross Join\"\n\t\t\t\tdata-response=\"1\"\n\t\t\t\tclass=\"wth-btn-rounded wth-yes-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t\tclass=\"feather feather-thumbs-up block w-full h-full\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> Yes <\/span>\n\t\t\t<\/button>\n\n\t\t\t<button\n\t\t\t\tdata-response=\"0\"\n\t\t\t\tdata-post=\"337\"\n\t\t\t\tdata-post-url=\"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-cross-join\/\"\n\t\t\t\tdata-post-title=\"PostgreSQL Cross Join\"\n\t\t\t\tclass=\"wth-btn-rounded wth-no-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M10 15v4a3 3 0 0 0 3 3l4-9V2H5.72a2 2 0 0 0-2 1.7l-1.38 9a2 2 0 0 0 2 2.3zm7-13h2.67A2.31 2.31 0 0 1 22 4v7a2.31 2.31 0 0 1-2.33 2H17\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> No <\/span>\n\t\t\t<\/button>\n\t\t<\/div>\n\t<\/header>\n\n\t<div class=\"wth-form hidden\">\n\t\t<div class=\"wth-form-wrapper\">\n\t\t\t<div class=\"wth-title\"><\/div>\n\t\t\t\n\t\t\t<textarea class=\"wth-message\"><\/textarea>\n\n\t\t\t<button class=\"btn btn-primary wth-btn-submit\">Send<\/button>\n\t\t\t<button class=\"btn wth-btn-cancel\">Cancel<\/button>\n\t\t\n\t\t<\/div>\n\t<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>You&#8217;ll learn how to use the PostgreSQL CROSS JOIN to merge rows from two tables and return all possible combinations of these rows.<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":13,"menu_order":27,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-337","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>PostgreSQL CROSS JOIN<\/title>\n<meta name=\"description\" content=\"You&#039;ll learn how to use the PostgreSQL CROSS JOIN to merge rows from two tables and return all possible combinations of these rows.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-cross-join\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PostgreSQL CROSS JOIN\" \/>\n<meta property=\"og:description\" content=\"You&#039;ll learn how to use the PostgreSQL CROSS JOIN to merge rows from two tables and return all possible combinations of these rows.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-cross-join\/\" \/>\n<meta property=\"og:site_name\" content=\"PostgreSQL Tutorial\" \/>\n<meta property=\"article:modified_time\" content=\"2025-02-10T07:58:57+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-tutorial\\\/postgresql-cross-join\\\/\",\"url\":\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-tutorial\\\/postgresql-cross-join\\\/\",\"name\":\"PostgreSQL CROSS JOIN\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-tutorial\\\/postgresql-cross-join\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-tutorial\\\/postgresql-cross-join\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.pgtutorial.com\\\/wp-content\\\/uploads\\\/2025\\\/02\\\/x-table-cross-join.svg\",\"datePublished\":\"2024-11-26T04:38:31+00:00\",\"dateModified\":\"2025-02-10T07:58:57+00:00\",\"description\":\"You'll learn how to use the PostgreSQL CROSS JOIN to merge rows from two tables and return all possible combinations of these rows.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-tutorial\\\/postgresql-cross-join\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-tutorial\\\/postgresql-cross-join\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-tutorial\\\/postgresql-cross-join\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.pgtutorial.com\\\/wp-content\\\/uploads\\\/2025\\\/02\\\/x-table-cross-join.svg\",\"contentUrl\":\"https:\\\/\\\/www.pgtutorial.com\\\/wp-content\\\/uploads\\\/2025\\\/02\\\/x-table-cross-join.svg\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/postgresql-tutorial\\\/postgresql-cross-join\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.pgtutorial.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PostgreSQL Tutorial\",\"item\":\"https:\\\/\\\/www.pgtutorial.com\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"PostgreSQL Cross Join\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/#website\",\"url\":\"https:\\\/\\\/www.pgtutorial.com\\\/\",\"name\":\"PostgreSQL Tutorial\",\"description\":\"Learn PostgreSQL from Scratch\",\"alternateName\":\"PostgreSQL\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.pgtutorial.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"PostgreSQL CROSS JOIN","description":"You'll learn how to use the PostgreSQL CROSS JOIN to merge rows from two tables and return all possible combinations of these rows.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-cross-join\/","og_locale":"en_US","og_type":"article","og_title":"PostgreSQL CROSS JOIN","og_description":"You'll learn how to use the PostgreSQL CROSS JOIN to merge rows from two tables and return all possible combinations of these rows.","og_url":"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-cross-join\/","og_site_name":"PostgreSQL Tutorial","article_modified_time":"2025-02-10T07:58:57+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-cross-join\/","url":"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-cross-join\/","name":"PostgreSQL CROSS JOIN","isPartOf":{"@id":"https:\/\/www.pgtutorial.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-cross-join\/#primaryimage"},"image":{"@id":"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-cross-join\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pgtutorial.com\/wp-content\/uploads\/2025\/02\/x-table-cross-join.svg","datePublished":"2024-11-26T04:38:31+00:00","dateModified":"2025-02-10T07:58:57+00:00","description":"You'll learn how to use the PostgreSQL CROSS JOIN to merge rows from two tables and return all possible combinations of these rows.","breadcrumb":{"@id":"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-cross-join\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-cross-join\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-cross-join\/#primaryimage","url":"https:\/\/www.pgtutorial.com\/wp-content\/uploads\/2025\/02\/x-table-cross-join.svg","contentUrl":"https:\/\/www.pgtutorial.com\/wp-content\/uploads\/2025\/02\/x-table-cross-join.svg"},{"@type":"BreadcrumbList","@id":"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-cross-join\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.pgtutorial.com\/"},{"@type":"ListItem","position":2,"name":"PostgreSQL Tutorial","item":"https:\/\/www.pgtutorial.com\/"},{"@type":"ListItem","position":3,"name":"PostgreSQL Cross Join"}]},{"@type":"WebSite","@id":"https:\/\/www.pgtutorial.com\/#website","url":"https:\/\/www.pgtutorial.com\/","name":"PostgreSQL Tutorial","description":"Learn PostgreSQL from Scratch","alternateName":"PostgreSQL","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.pgtutorial.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/pages\/337","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/comments?post=337"}],"version-history":[{"count":10,"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/pages\/337\/revisions"}],"predecessor-version":[{"id":1980,"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/pages\/337\/revisions\/1980"}],"up":[{"embeddable":true,"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/pages\/13"}],"wp:attachment":[{"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/media?parent=337"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}