需要SQL语法

时间:2012-10-03 22:43:00

标签: sql

我在sql中有3个表,看起来像这样:(需要sql语法)

1

.xy8vx_users
-username
-email
-....

2

.xy8vx_rsform_submissions
-SubmissionId
-Username
-...

3

.xy8vx_rsform_submissions_values
-SubmissionId
-FieldName
-FieldValue
-...

我想得到:  xy8vx_users.username, and xy8vx_users.email,满足条件

submission_values.FieldName = 'data2' AND submission_values.FieldValue = '10.03.2012'

我花了2个小时,没有人可以帮助我?

我试过这个:(但没有工作)

SELECT sub.Username
FROM `xy8vx_rsform_submission_values` AS value
JOIN `xy8vx_rsform_submissions` AS sub ON value.SubmissionId = sub.SubmissionId
JOIN xy8vx_users ` AS users ON sub.Username = users.email WHERE value.FieldName = 'data2' AND value.FieldValue = '10.03.2012'`

1 个答案:

答案 0 :(得分:1)

select xy8vx_users.username, xy8vx_users,email
from
submission_values 
inner join
submissions on 
submission_values.SubmissionId = submissions.SubmissionId
inner join
xy8vx_users on
submissions.Username = xy8vx_users.username
where 
submission_values.FieldName = 'data2'
and 
submission_values.FieldValue = '10.03.2012'