请帮我解决这个问题, 我有2个mysql表,
tbl_product
id name title userID
1 Phone N95 1
2 Tab Google 1
3 Laptop Toshiba 1
4 PhoneNext Nokia 2
5 Mp3 Player Apple 2
6 Gallexy Samsung 3
7 Hard 320GB 6
tbl_user
id selName
1 Jhon
2 Khan
3 Mohomad
4 Ann
6 Ricky
我需要得到这个输出加入这两个表,
Phone N95 (userID = 1)
Tab Google (userID = 1)
Laptop Toshiba (userID = 1)
Jhon(id = 1)
PhoneNext Nokia (userID = 2)
Mp3 Player Apple (userID = 2)
汗(id = 2)
Gallexy Samsung (userID = 3)
Mohomad(id = 3)
请帮助我们各位感谢....
I Need to get Like This out put,
<table width="224" border="1"> <tr> <td width="214">Phone N95 (userID = 1)</td> </tr> <tr> <td>Tab Google (userID = 1)</td> </tr> <tr> <td>Laptop Toshiba (userID = 1)</td> </tr> <tr> <td align="right" bgcolor="#FFFF99">Jhon (id=1)</td> </tr> <tr> <td>PhoneNext Nokia (userID = 2)</td> </tr> <tr> <td>Mp3 Player Apple (userID = 2)</td> </tr> <tr> <td align="right" bgcolor="#FFFF99">Khan (id=2)</td> </tr> </table>
答案 0 :(得分:0)
你不能用这样的东西吗?
Select title,userID from tbl_product
where tbl_product.userID = tbl_user.id
group by userID
答案 1 :(得分:0)
SELECT tbl_product.userID, tbl_product.name, tbl_product.title, tbl_user.selName
FROM tbl_product
LEFT JOIN tbl_user ON tbl_product.userID = tbl_user.id
GROUP BY tbl_product.userID
我建议您开始阅读有关MySQL的基础知识。