STRAIGHT_JOIN
Example
Section titled “Example”SELECT STRAIGHT_JOIN orders.order_id, products.product_nameFROM ordersSTRAIGHT_JOIN productsON orders.product_id = products.product_idLIMIT 10;Output
Section titled “Output”| order_id | product_name ||----------|----------------|| 1 | Laptop || 2 | Mobile Phone || 3 | Television || 4 | Refrigerator || 5 | Washing Machine|| 6 | Oven || 7 | Microwave || 8 | Blender || 9 | Toaster || 10 | Fridge |Explanation
Section titled “Explanation”The STRAIGHT_JOIN keyword in MySQL enforces the table join order based on how the tables appear in the query. In this example, we join ‘orders’ and ‘products’ tables based on the product_id. The join sequence begins with the ‘orders’ table, matching records from the ‘products’ table. This shows the first 10 records of order_id and corresponding product_name.