SQL Server error 1013, "The objects in the FROM clause are not related," appears when a query joins tables that have no defined relationship. The fix is to add an explicit JOIN with an ON condition, or to correct the join condition so it actually links the tables. The error is not a corruption or licensing problem; it is the query optimizer telling you that the tables in your FROM clause are unrelated.

What You'll Need

  • Access to SQL Server Management Studio (SSMS) or another client such as Azure Data Studio, with permission to run the query.
  • The name of the database and the tables involved in the failing query.
  • Knowledge of the columns that link the tables (for example, a shared customer ID).
  • Optional: the execution plan or the full error message text, which helps identify the exact statement.

Step-by-Step

  1. Read the full error message. Error 1013 usually includes the names of the objects that are not related. Write down those table names. If the message is truncated, run the query in SSMS and check the Messages tab for the complete text.
  2. Locate the FROM clause in the failing query. Identify every table, view, or table-valued function listed there. Pay attention to comma-separated tables, because older-style joins are a common trigger.
  3. Check for a missing JOIN condition. If the query lists two tables separated by a comma and the WHERE clause does not compare a column from one table to a column from the other, SQL Server cannot relate them. Add an explicit INNER JOIN or LEFT JOIN with an ON clause that links the tables.
  4. Verify the join columns exist and have compatible data types. A join on int to varchar may still run, but a join on columns that do not exist will fail. Confirm the column names in both tables using sp_help or Object Explorer.
  5. Look for a cross join written by accident. A missing join predicate turns into a Cartesian product, and SQL Server may raise 1013 when it cannot infer a relationship. Add the missing predicate or, if a cross join is intentional, write CROSS JOIN explicitly.
  6. Check views and table-valued functions. If the FROM clause includes a view, open its definition and confirm it returns a related set. A view that itself contains a cross join can cause the outer query to fail.
  7. Rewrite old-style joins. Replace comma joins with INNER JOIN ... ON ... syntax. This makes the relationship explicit and prevents the optimizer from guessing.
  8. Test the corrected query. Run it with a small result set first, for example by adding TOP 10. If it returns rows, remove the limit and run the full query.
  9. Save and document the fix. Add a comment above the join explaining the relationship, so the next person does not reintroduce the comma join.

Common Mistakes

  • Joining on the wrong column. Two tables may both have an ID column, but they may not represent the same entity. Joining Orders.CustomerID to Products.ProductID will not relate the tables correctly.
  • Using WHERE instead of ON. Putting the join condition in the WHERE clause works for inner joins but changes the meaning of outer joins. Keep the relationship in the ON clause.
  • Forgetting the second table in a multi-table join. In a three-table join, each new table needs its own ON condition. Missing one leaves that table unrelated.
  • Assuming the error means data is missing. Error 1013 is about query structure, not missing rows. The tables can be full of data and still be unrelated in the query.
  • Editing the view instead of the query. If the problem is in the outer query, changing the view will not help and may break other reports.

Tips

  • Use table aliases (o for Orders, c for Customers) to keep join conditions readable and to avoid ambiguous column errors.
  • Format each join on its own line. This makes missing ON clauses obvious during review.
  • When you inherit a query, run it with SET SHOWPLAN_TEXT ON to see how SQL Server interprets the joins before you change anything.
  • Keep a copy of the original query before editing. If the fix makes results worse, you can compare row counts.
  • Use INNER JOIN when you only want matching rows, and LEFT JOIN when you need all rows from one table. The choice affects which rows appear, not whether error 1013 occurs.

Troubleshooting

If the error persists after adding a join condition, check whether the query uses a table-valued function that returns an unrelated rowset. Some functions return a single column that must be joined to a specific key; confirm the function's output columns. If the query involves linked servers or synonyms, verify that the synonym points to the expected table and that the linked server login has permission to read it. Permission errors usually produce a different message, but a synonym pointing to the wrong object can look like an unrelated table.

If the query runs in one database but fails in another, compare the schema. A column may have been renamed, or a view may have been altered. Script out both objects and compare their definitions. If the error appears only in a stored procedure, check for dynamic SQL inside it; the error may come from a string built at runtime, and the line number in the message may point to the procedure rather than the generated statement.

If you cannot find the missing relationship, simplify the query. Remove tables one at a time until the error disappears, then add them back with explicit joins. This isolates the unrelated pair. Do not disable or bypass security features to make the query run; fix the join instead.

Frequently Asked Questions

What causes SQL Server error 1013?

It occurs when the tables in the FROM clause have no join condition linking them, so SQL Server cannot determine how they relate.

Does error 1013 mean my data is corrupted?

No. It is a query syntax and relationship error, not a database corruption or hardware problem.

Can I fix it by adding a WHERE clause?

For inner joins, a WHERE condition that compares columns from both tables can work, but explicit JOIN ... ON syntax is clearer and safer, especially with outer joins.

Why does the query work in one database but not another?

The schemas likely differ. A column may be missing or renamed, or a view may have been changed. Compare the object definitions in both databases.

Is error 1013 the same as a Cartesian product?

They are related. A missing join condition can produce a Cartesian product, and SQL Server may raise 1013 when it cannot infer a relationship. Writing explicit joins prevents both.

Do I need to change the database compatibility level?

No. Error 1013 is about the query's FROM clause, not the compatibility level. Changing the level will not fix an unrelated join.