'how to select all from one table and one only from another linked with foreign key
database table
1.products,
2.productsImg - productID as foreign key
want to select * from products and one image per product from productsImg using mysql
Solution 1:[1]
Try this sql:
select p.*, pi.name from products p join productsImg pi on pi.productId=p.id group by p.id
Here I am assuming "name" field in productsImg table has image name.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
