code
SELECT p.*, c.ID, c.Description as CategoryName
FROM Products p, Categories c
where p.CategoryID=c.ID
Explanation
This will select everything from products table and only ‘ID’ and ‘Description’ from categories table given the category IDs are same. Note that the alias for ‘Products’ table is p and Alias for ‘Categories’ table is c. Column ‘Description’ of categories table will be shown as ‘CategoryName’ in the resultant table as the alias for that column is ‘CategoryName’. The aliases are only the temporary names that can be viewed when the query executes.
Leave a comment