diff --git a/e2e/test/scenarios/question-reproductions/reproductions-3.cy.spec.js b/e2e/test/scenarios/question-reproductions/reproductions-3.cy.spec.js
index e6df32013f5440140d52377e5b2ff9ffafc907f5..75257520d5a56317da719ccdc4bfc59516c75adf 100644
--- a/e2e/test/scenarios/question-reproductions/reproductions-3.cy.spec.js
+++ b/e2e/test/scenarios/question-reproductions/reproductions-3.cy.spec.js
@@ -36,7 +36,7 @@ import {
   addCustomColumn,
 } from "e2e/support/helpers";
 
-const { ORDERS, ORDERS_ID, PRODUCTS } = SAMPLE_DATABASE;
+const { ORDERS, ORDERS_ID, PRODUCTS, PRODUCTS_ID } = SAMPLE_DATABASE;
 
 describe("issue 32625, issue 31635", () => {
   const CC_NAME = "Is Promotion";
@@ -931,3 +931,66 @@ describe("issue 43294", () => {
     });
   });
 });
+
+describe("issue 40399", () => {
+  beforeEach(() => {
+    restore();
+    cy.signInAsAdmin();
+  });
+
+  it("should not show results from other stages in a stages preview (metabase#40399)", () => {
+    createQuestion(
+      {
+        name: "40399",
+        query: {
+          "source-table": PRODUCTS_ID,
+          joins: [
+            {
+              fields: "all",
+              alias: "Orders",
+              "source-table": ORDERS_ID,
+              strategy: "left-join",
+              condition: [
+                "=",
+                ["field", PRODUCTS.ID, null],
+                ["field", ORDERS.PRODUCT_ID, { "join-alias": "Orders" }],
+              ],
+            },
+          ],
+          filter: ["=", ["field", PRODUCTS.CATEGORY, null], "Widget"],
+        },
+      },
+      {
+        visitQuestion: true,
+      },
+    );
+
+    openNotebook();
+
+    getNotebookStep("filter", { stage: 0 }).within(() => {
+      cy.icon("play").click();
+      cy.findByTestId("preview-root")
+        .findAllByText("Widget")
+        .should("be.visible");
+    });
+
+    getNotebookStep("join", { stage: 0 }).within(() => {
+      cy.icon("play").click();
+      cy.findByTestId("preview-root")
+        .findAllByText("Gizmo")
+        .should("be.visible");
+
+      cy.findByTestId("preview-root").findByText("Widget").should("not.exist");
+    });
+
+    getNotebookStep("data", { stage: 0 }).within(() => {
+      cy.icon("play").click();
+      cy.findByTestId("preview-root")
+        .findAllByText("Gizmo")
+        .should("be.visible");
+
+      cy.findByTestId("preview-root").findAllByText("Gizmo").should("exist");
+      cy.findByTestId("preview-root").findAllByText("Widget").should("exist");
+    });
+  });
+});
diff --git a/frontend/src/metabase/query_builder/components/notebook/NotebookStep/NotebookStep.tsx b/frontend/src/metabase/query_builder/components/notebook/NotebookStep/NotebookStep.tsx
index 9c8731c4b56eed9f65f84743aeb4674bf871fbb6..8f5d0b25f868677393a8e35faf73ac27e871982c 100644
--- a/frontend/src/metabase/query_builder/components/notebook/NotebookStep/NotebookStep.tsx
+++ b/frontend/src/metabase/query_builder/components/notebook/NotebookStep/NotebookStep.tsx
@@ -160,6 +160,7 @@ function NotebookStep({
                   transparent
                   hasPreviewButton={hasPreviewButton}
                   onClick={openPreview}
+                  data-testid="step-preview-button"
                 />
               </StepButtonContainer>
             )}