Skip to content

Instantly share code, notes, and snippets.

@carylee
Created October 7, 2011 18:26
Show Gist options
  • Save carylee/1271012 to your computer and use it in GitHub Desktop.
Save carylee/1271012 to your computer and use it in GitHub Desktop.
Webform responses query
SELECT all1.nid as nid, all1.email as email, all1.submitted as submitted, all1.node_uid as node_uid, all2.form_key as answer_type,
all2.name as question, all2.response_uid as response_uid
FROM
(SELECT rest.nid, rest.response, rest.email, rest.sid, rest.submitted, rest.response_uid, rest.node_uid, form_key, name, type
FROM (SELECT wsd1.nid as nid,
wsd1.data as response, wsd2.data as email, wsd1.sid as sid, ws.submitted, ws.uid as response_uid, node.uid as node_uid
FROM webform_submitted_data wsd1
JOIN webform_submitted_data wsd2 ON wsd1.sid=wsd2.sid
JOIN webform_submissions ws ON wsd1.sid=ws.sid
JOIN node ON node.nid=wsd1.nid
WHERE wsd1.cid < wsd2.cid) rest
JOIN webform_component wc
ON wc.nid = rest.nid) all1
JOIN
(SELECT rest.nid, rest.response, rest.email, rest.sid, rest.submitted, rest.response_uid, rest.node_uid, form_key, name, type
FROM (SELECT wsd1.nid as nid,
wsd1.data as response, wsd2.data as email, wsd1.sid as sid, ws.submitted, ws.uid as response_uid, node.uid as node_uid
FROM webform_submitted_data wsd1
JOIN webform_submitted_data wsd2 ON wsd1.sid=wsd2.sid
JOIN webform_submissions ws ON wsd1.sid=ws.sid
JOIN node ON node.nid=wsd1.nid
WHERE wsd1.cid < wsd2.cid) rest
JOIN webform_component wc
ON wc.nid = rest.nid) all2
ON all1.nid=all2.nid
AND all1.sid=all2.sid
AND all1.email=all2.email
WHERE all1.form_key <> all2.form_key
AND all1.form_key = "email"
ORDER BY all1.nid DESC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment