diff --git a/frontend/src/metabase-lib/lib/queries/StructuredQuery.ts b/frontend/src/metabase-lib/lib/queries/StructuredQuery.ts
index 3b8d9e2a8f717516563860919b86c477fe54e67f..75d4da6f0af2c1578cbe9790f8420525aa57b7e9 100644
--- a/frontend/src/metabase-lib/lib/queries/StructuredQuery.ts
+++ b/frontend/src/metabase-lib/lib/queries/StructuredQuery.ts
@@ -1162,7 +1162,7 @@ class StructuredQueryInner extends AtomicQuery {
       }
     }
 
-    if (this.isRaw()) {
+    if (this.isRaw() && this.sourceQuery()) {
       query = query.clearFields();
     }
 
diff --git a/frontend/src/metabase/visualizations/components/TableInteractive.jsx b/frontend/src/metabase/visualizations/components/TableInteractive.jsx
index 15fcbd72d290693d5d3673ec8fa5140597f34945..e2ed11ac0e7c39ffbbfa3ef7157da91cc3f3baa3 100644
--- a/frontend/src/metabase/visualizations/components/TableInteractive.jsx
+++ b/frontend/src/metabase/visualizations/components/TableInteractive.jsx
@@ -709,6 +709,7 @@ class TableInteractive extends Component {
         }}
       >
         <div
+          data-testid="header-cell"
           ref={e => (this.headerRefs[columnIndex] = e)}
           style={{
             ...style,
diff --git a/frontend/test/metabase/scenarios/question/reproductions/23023-preview-shows-hidden-columns.cy.spec.js b/frontend/test/metabase/scenarios/question/reproductions/23023-preview-shows-hidden-columns.cy.spec.js
new file mode 100644
index 0000000000000000000000000000000000000000..43e82a0279e38347adcca9f25f3fbce20df6ed77
--- /dev/null
+++ b/frontend/test/metabase/scenarios/question/reproductions/23023-preview-shows-hidden-columns.cy.spec.js
@@ -0,0 +1,58 @@
+import {
+  restore,
+  visitQuestionAdhoc,
+  openNotebook,
+} from "__support__/e2e/cypress";
+import { SAMPLE_DB_ID } from "__support__/e2e/cypress_data";
+import { SAMPLE_DATABASE } from "__support__/e2e/cypress_sample_database";
+
+const { ORDERS, ORDERS_ID, PRODUCTS, PRODUCTS_ID } = SAMPLE_DATABASE;
+
+const questionDetails = {
+  display: "table",
+  dataset_query: {
+    database: SAMPLE_DB_ID,
+    query: {
+      "source-table": ORDERS_ID,
+      joins: [
+        {
+          fields: [["field", PRODUCTS.CATEGORY, { "join-alias": "Products" }]],
+          "source-table": PRODUCTS_ID,
+          condition: [
+            "=",
+            ["field", ORDERS.PRODUCT_ID, null],
+            ["field", PRODUCTS.ID, { "join-alias": "Products" }],
+          ],
+          alias: "Products",
+        },
+      ],
+      fields: [
+        ["field", ORDERS.ID, null],
+        ["field", ORDERS.PRODUCT_ID, null],
+      ],
+    },
+    type: "query",
+  },
+};
+
+describe("issue 23023", () => {
+  beforeEach(() => {
+    restore();
+    cy.signInAsAdmin();
+  });
+
+  it("should show only selected columns in a step preview (metabase#23023)", () => {
+    visitQuestionAdhoc(questionDetails);
+
+    openNotebook();
+
+    cy.icon("play")
+      .eq(1)
+      .click();
+
+    cy.findAllByTestId("header-cell").contains("Products → Category");
+    cy.findAllByTestId("header-cell")
+      .contains("Tax")
+      .should("not.exist");
+  });
+});