# Referencing a Column

## **What is qualifying column reference?**

A qualifying column reference is a column reference that is prefixed with the name of the table that the column belongs to. For example, if the table `customers` has a column called `name`, then the qualifying column reference for that column would be `customers.name`.

### **Why use qualifying column references?**

There are two main reasons why you might want to use qualifying column references:

* To avoid ambiguity. If you have two columns with the same name in different tables, then using qualifying column references will make it clear which column you are referring to.
* To improve performance. When you use qualifying column references, the database can more easily optimize your queries.

## **Rules for qualifying column references**

There are a few rules that you need to follow when using qualifying column references:

* The table name must be enclosed in parentheses.
* The column name must not be enclosed in parentheses.
* You can use qualifying column references in any place where you would normally use a column name.

**Here is an example of a qualifying column reference in SQL:**

```sql
SELECT customers.name, customers.age
FROM customers;
```

This query will select the `name` and `age` columns from the `customers` table. The qualifying column references (`customers.name` and `customers.age`) make it clear that we are referring to the columns in the `customers` table, and not any other columns with the same names.

**Visualizing qualifying column references**

Here is a visualization of qualifying column references:

```sql
+------+------+
| Table | Column |
+------+------+
| customers | name |
| customers | age |
+------+------+
```

The table on the left represents the `customers` table. The column on the right represents the `name` column in the `customers` table. The qualifying column reference for this column would be `customers.name`.

## **Proper syntax with SQL code block**

Here is the proper syntax for qualifying column references in SQL:

```sql
SELECT table_name.column_name
FROM table_name;
```

For example, the following query would select the `name` column from the `customers` table:

```sql
SELECT customers.name
FROM customers;
```


---

# Agent Instructions: 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://qatesting.gitbook.io/qa/database-testing/sql/referencing-a-column.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.
