Chapter-15 : Self Join & Table Alias in SQL with example | MySQL database

Publicado el: 03 noviembre 2023
en el canal de: All about data
147
4

Self Join & Table Alias in SQL with example | MySQL database

📺 YouTube :    / @all_about_data_  
📷 Instagram :   / allabout_da.  .
📺Google Drive : https://drive.google.com/drive/folder...


Self join in SQL is a join that is performed between a table and itself. This can be useful for tasks such as finding hierarchical data or comparing rows within the same table.

To perform a self join in SQL, you use the JOIN or INNER JOIN clause and specify the table name twice. You can also use table aliases to make the query more readable.


Self join in SQL is a join that is performed between a table and itself. This can be useful for tasks such as finding hierarchical data or comparing rows within the same table.

To perform a self join in SQL, you use the JOIN or INNER JOIN clause and specify the table name twice. You can also use table aliases to make the query more readable.

For example, the following query will find all customers who have placed an order with themselves:

SQL
SELECT c1.customer_id, c1.name, c2.name AS ordered_from
FROM customers c1
INNER JOIN customers c2 ON c1.customer_id = c2.ordered_by_customer_id;
Use code with caution. Learn more
This query will return all rows from the customers table where the customer_id column is equal to the ordered_by_customer_id column.




Table aliases in SQL are used to give a table a different name for the purpose of a query. This can be useful when you are joining two tables with the same name or when you are trying to make your query more readable.

To create a table alias, you use the AS keyword. For example, the following query will join the customers table to itself and use the aliases c1 and c2:


En esta página del sitio puede ver el video en línea Chapter-15 : Self Join & Table Alias in SQL with example | MySQL database de Duración hora minuto segunda en buena calidad , que subió el usuario All about data 03 noviembre 2023, comparta el enlace con amigos y conocidos, en youtube este video ya ha sido visto 147 veces y le gustó 4 a los espectadores. Disfruta viendo!