> For the complete documentation index, see [llms.txt](https://web.tipsytux.in/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://web.tipsytux.in/server-side/sql-injection/examples/union-based.md).

# Union Based

For a `UNION` query to work, two key requirements must be met:&#x20;

1. The individual queries must return the same number of columns.&#x20;
2. The data types in each column must be compatible with the individual queries.

***

## Steps

1. Determine the number of columns required in SQL injection to view the output.
   1. ' ORDER BY 1--&#x20;
   2. ' ORDER BY 2--&#x20;
   3. ' ORDER BY 3-- etc.
2. The aim here is we get an error when the number of columns is more than expected for the query.

***


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://web.tipsytux.in/server-side/sql-injection/examples/union-based.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
