<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="bbPress/1.0.1" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>Gravity Support Forums Topic: How to query database</title>
		<link>https://legacy.forums.gravityhelp.com/topic/how-to-query-database</link>
		<description>Gravity Support Forums Topic: How to query database</description>
		<language>en-US</language>
		<pubDate>Sun, 19 Apr 2026 23:22:30 +0000</pubDate>
		<generator>http://bbpress.org/?v=1.0.1</generator>
		<textInput>
			<title><![CDATA[Search]]></title>
			<description><![CDATA[Search all topics from these forums.]]></description>
			<name>q</name>
			<link>https://legacy.forums.gravityhelp.com/search.php</link>
		</textInput>
		<atom:link href="https://legacy.forums.gravityhelp.com/rss/topic/how-to-query-database" rel="self" type="application/rss+xml" />

		<item>
			<title>mobilus on "How to query database"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/how-to-query-database#post-52887</link>
			<pubDate>Mon, 19 Mar 2012 15:34:35 +0000</pubDate>
			<dc:creator>mobilus</dc:creator>
			<guid isPermaLink="false">52887@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Thanks for taking the time to detail your solution.  This will definitely help.  Cheers,&#60;br /&#62;
Mike
&#60;/p&#62;</description>
		</item>
		<item>
			<title>placson on "How to query database"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/how-to-query-database#post-52881</link>
			<pubDate>Mon, 19 Mar 2012 15:03:23 +0000</pubDate>
			<dc:creator>placson</dc:creator>
			<guid isPermaLink="false">52881@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;I had to do a complicated subquery in order to get my results.  There's no native way to read the field_number values from the wp_rg_form table to get the column names.  Essentially the problem is that Gravity Forms allows for dynamic tables by creating rows in the wp_rg_lead_detail table.  To display your rows as a column you have to do a row to column, pivot table.  To achieve this a sub query is required.  My query ended up looking like this mess:&#60;/p&#62;
&#60;p&#62;1) I created a view called 'bjj'&#60;/p&#62;
&#60;p&#62;&#60;code&#62;create view bjj as select * from wp_rg_lead_detail where form_id=1&#60;/code&#62;&#60;/p&#62;
&#60;p&#62;2) My query looked like this madness:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;select lead_id as entryId
,(select value from bjj where field_number=1 and lead_id = entryId) as email
,(select value from bjj where round(field_number,2) = 2.3 and lead_id = entryId) as first_name
,(select value from bjj where round(field_number,2) = 2.6 and lead_id = entryId) as last_name
,(select value from bjj where round(field_number,2) = 5.1 and lead_id = entryId) as address1
,(select value from bjj where round(field_number,2) = 5.2 and lead_id = entryId) as address2
,(select value from bjj where round(field_number,2) = 5.3 and lead_id = entryId) as city
,(select value from bjj where round(field_number,2) = 5.4 and lead_id = entryId) as state
,(select value from bjj where round(field_number,2) = 5.5 and lead_id = entryId) as zip
,(select value from bjj where round(field_number,2) = 5.6 and lead_id = entryId) as country
,(select value from bjj where round(field_number,2) = 63.0 and lead_id = entryId) as phone
,(select value from bjj where round(field_number,2) = 66.0 and lead_id = entryId) as age
from bjj
group by entryId order by entryId&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;Since GF uses floats for the field_number you have to accomodate by doing the ugly round(...).  You have to know firsthand what your field_numbers map to.  In my case I had to manually examine the field_number/values pair to find out what they were mapped to (e.g. 66.0 mapped to the age column).&#60;/p&#62;
&#60;p&#62;Hope that helps you out.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>mobilus on "How to query database"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/how-to-query-database#post-52876</link>
			<pubDate>Mon, 19 Mar 2012 13:48:56 +0000</pubDate>
			<dc:creator>mobilus</dc:creator>
			<guid isPermaLink="false">52876@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;I'm also interested in learning how to generate a list of my entries.  If you get help, can you post your findings.  thanks, Mike
&#60;/p&#62;</description>
		</item>
		<item>
			<title>placson on "How to query database"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/how-to-query-database#post-52593</link>
			<pubDate>Thu, 15 Mar 2012 15:46:51 +0000</pubDate>
			<dc:creator>placson</dc:creator>
			<guid isPermaLink="false">52593@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Hello?  Any help out there?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>placson on "How to query database"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/how-to-query-database#post-52315</link>
			<pubDate>Tue, 13 Mar 2012 19:30:17 +0000</pubDate>
			<dc:creator>placson</dc:creator>
			<guid isPermaLink="false">52315@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Hi there.. is this possible to do from SQL or do I have to deserialize the strings stored in the form table?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>placson on "How to query database"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/how-to-query-database#post-52174</link>
			<pubDate>Mon, 12 Mar 2012 19:10:52 +0000</pubDate>
			<dc:creator>placson</dc:creator>
			<guid isPermaLink="false">52174@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;I've looked at the wp_rg tables and I found that this query will return all the fields and their values.  However the field_number is just a number.  Where are the values for the field_number stored?&#60;/p&#62;
&#60;p&#62; select id, field_number, value from wp_rg_lead_detail where form_id=1;&#60;/p&#62;
&#60;p&#62;I have 3 forms and the 1st form has form_id = 1.  The values returned are:&#60;/p&#62;
&#60;p&#62;&#124; 17971 &#124;5.3&#124; Stockton&#60;br /&#62;
&#124; 17972 &#124;5.4 &#124; California&#60;br /&#62;
&#124; 17973 &#124;5.5 &#124; 95212&#60;/p&#62;
&#60;p&#62;Where are my field_number values?
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
