我在mySQL db中有两个表(photoentry和member)。当用户登录时,我会根据他们用于登录的电子邮件从成员表中检索所有在那里的用户详细信息。
String sql = "SELECT * FROM member WHERE email='"+email+"'";
并显示如下结果:
<td><b>Member ID: </b></td><td><input type="text" name="id" value="<%=resultSet.getString("id")%>"/> ></td>
我想使用此成员ID来检索与用户关联的照片条目。我尝试过
String sql = "SELECT * FROM photoentry p where (SELECT id from member m WHERE p.m_ID = m.id AND email='"+email+"'";
如何使用原始查询的结果集检索与该成员关联的光条目? (我正在使用JSP)
答案 0 :(得分:1)
请尝试这个。
String sql = "
SELECT p.* FROM photoentry AS p
INNER JOIN member AS m ON
p.member_id = m.id
WHERE m.email LIKE '"+email+"'";
答案 1 :(得分:0)
您可以这样做:
String sql = "
SELECT * FROM photoentry AS p
JOIN member AS m ON (p.member_id = m.id)
WHERE m.email LIKE '"+email+"'";