473,568 Members | 2,850 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SQL Help Please

Hello,

I would like to model and implement a simple application for keeping
track of user survey data for our marketing department.

The concept is very simple: a user of our website can opt-in to answer
a short list of questions for data collection.

The answers to all of the questions are presented in drop-down boxes,
so no free form text is stored.

We would like to store all of the questions, answer options, and user
answers in the database.

I have three simple tables to present (all fields are NOT NULL)

questions
--------------
question_id int(11)
question_text varchar(255)

answer_options
--------------
answer_option_i d int(11)
question_id int(11)
answer_option_t ext varchar(255)

user_answers
--------------
user_answer_id int(11)
question_id int(11)
answer_option_i d int(11)
user_id int(11)

What I'm scratching my brain trying to solve is how to construct the
appropriate SQL statement to, in one query, select all questions, all
answers, and those answers that a specific user_id has already
selected.

Something akin to:

SELECT q.question_id,
q.question_text ,
ao.answer_optio n_text,
ao.answer_optio n_id,
ua.user_answer_ id
FROM questions q, answer_options ao, user_answers ua
WHERE ????

The end result would have a not null user_answer_id where the user has
made a choice.

I have been trying with LEFT OUTER JOINS, and am thinking that a
subquery of user_answers by user_id into a temp table might be needed,
though I've never attempted one first.

Any generous folk out there mind posting up some SQL that would work?

many thanks for the help!

cheers!

Hal
Jul 19 '05 #1
3 1554
How about:

SELECT q.question_id,
q.question_text ,
ao.answer_optio n_text,
ao.answer_optio n_id,
ua.user_answer_ id
FROM
questions q,
answer_options ao
LEFT JOIN
user_answers ua
ON
${user_id}=ua.u ser_id AND ao.answer_optio n_id=ua.answer_ option_id
WHERE
ao.question_id= q.question_id
ORDER BY
q.question_id, ao.answer_optio n_id

Appears to work. Any comments on improvements?

ha***********@y ahoo.com (Hal Robertson) wrote in message news:<a8******* *************** ***@posting.goo gle.com>...
Hello,

I would like to model and implement a simple application for keeping
track of user survey data for our marketing department.

The concept is very simple: a user of our website can opt-in to answer
a short list of questions for data collection.

The answers to all of the questions are presented in drop-down boxes,
so no free form text is stored.

We would like to store all of the questions, answer options, and user
answers in the database.

I have three simple tables to present (all fields are NOT NULL)

questions
--------------
question_id int(11)
question_text varchar(255)

answer_options
--------------
answer_option_i d int(11)
question_id int(11)
answer_option_t ext varchar(255)

user_answers
--------------
user_answer_id int(11)
question_id int(11)
answer_option_i d int(11)
user_id int(11)

What I'm scratching my brain trying to solve is how to construct the
appropriate SQL statement to, in one query, select all questions, all
answers, and those answers that a specific user_id has already
selected.

Something akin to:

SELECT q.question_id,
q.question_text ,
ao.answer_optio n_text,
ao.answer_optio n_id,
ua.user_answer_ id
FROM questions q, answer_options ao, user_answers ua
WHERE ????

The end result would have a not null user_answer_id where the user has
made a choice.

I have been trying with LEFT OUTER JOINS, and am thinking that a
subquery of user_answers by user_id into a temp table might be needed,
though I've never attempted one first.

Any generous folk out there mind posting up some SQL that would work?

many thanks for the help!

cheers!

Hal

Jul 19 '05 #2
How about:

SELECT q.question_id,
q.question_text ,
ao.answer_optio n_text,
ao.answer_optio n_id,
ua.user_answer_ id
FROM
questions q,
answer_options ao
LEFT JOIN
user_answers ua
ON
${user_id}=ua.u ser_id AND ao.answer_optio n_id=ua.answer_ option_id
WHERE
ao.question_id= q.question_id
ORDER BY
q.question_id, ao.answer_optio n_id

Appears to work. Any comments on improvements?

ha***********@y ahoo.com (Hal Robertson) wrote in message news:<a8******* *************** ***@posting.goo gle.com>...
Hello,

I would like to model and implement a simple application for keeping
track of user survey data for our marketing department.

The concept is very simple: a user of our website can opt-in to answer
a short list of questions for data collection.

The answers to all of the questions are presented in drop-down boxes,
so no free form text is stored.

We would like to store all of the questions, answer options, and user
answers in the database.

I have three simple tables to present (all fields are NOT NULL)

questions
--------------
question_id int(11)
question_text varchar(255)

answer_options
--------------
answer_option_i d int(11)
question_id int(11)
answer_option_t ext varchar(255)

user_answers
--------------
user_answer_id int(11)
question_id int(11)
answer_option_i d int(11)
user_id int(11)

What I'm scratching my brain trying to solve is how to construct the
appropriate SQL statement to, in one query, select all questions, all
answers, and those answers that a specific user_id has already
selected.

Something akin to:

SELECT q.question_id,
q.question_text ,
ao.answer_optio n_text,
ao.answer_optio n_id,
ua.user_answer_ id
FROM questions q, answer_options ao, user_answers ua
WHERE ????

The end result would have a not null user_answer_id where the user has
made a choice.

I have been trying with LEFT OUTER JOINS, and am thinking that a
subquery of user_answers by user_id into a temp table might be needed,
though I've never attempted one first.

Any generous folk out there mind posting up some SQL that would work?

many thanks for the help!

cheers!

Hal

Jul 19 '05 #3
How about:

SELECT q.question_id,
q.question_text ,
ao.answer_optio n_text,
ao.answer_optio n_id,
ua.user_answer_ id
FROM
questions q,
answer_options ao
LEFT JOIN
user_answers ua
ON
${user_id}=ua.u ser_id AND ao.answer_optio n_id=ua.answer_ option_id
WHERE
ao.question_id= q.question_id
ORDER BY
q.question_id, ao.answer_optio n_id

Appears to work. Any comments on improvements?

ha***********@y ahoo.com (Hal Robertson) wrote in message news:<a8******* *************** ***@posting.goo gle.com>...
Hello,

I would like to model and implement a simple application for keeping
track of user survey data for our marketing department.

The concept is very simple: a user of our website can opt-in to answer
a short list of questions for data collection.

The answers to all of the questions are presented in drop-down boxes,
so no free form text is stored.

We would like to store all of the questions, answer options, and user
answers in the database.

I have three simple tables to present (all fields are NOT NULL)

questions
--------------
question_id int(11)
question_text varchar(255)

answer_options
--------------
answer_option_i d int(11)
question_id int(11)
answer_option_t ext varchar(255)

user_answers
--------------
user_answer_id int(11)
question_id int(11)
answer_option_i d int(11)
user_id int(11)

What I'm scratching my brain trying to solve is how to construct the
appropriate SQL statement to, in one query, select all questions, all
answers, and those answers that a specific user_id has already
selected.

Something akin to:

SELECT q.question_id,
q.question_text ,
ao.answer_optio n_text,
ao.answer_optio n_id,
ua.user_answer_ id
FROM questions q, answer_options ao, user_answers ua
WHERE ????

The end result would have a not null user_answer_id where the user has
made a choice.

I have been trying with LEFT OUTER JOINS, and am thinking that a
subquery of user_answers by user_id into a temp table might be needed,
though I've never attempted one first.

Any generous folk out there mind posting up some SQL that would work?

many thanks for the help!

cheers!

Hal

Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2155
by: Numberwhun | last post by:
Hello everyone! I am trying to learn java and have run into kind of a snag. Here is the code that I have so far: ------ <begin_code> ---------- import javax.swing.*; import javax.swing.JApplet; import javax.swing.JOptionPane; import java.awt.Graphics;
1
1978
by: HolaGoogle | last post by:
Hi all, Please help me with the following..it's realy urgent and i tried everything i could and i can't get it work properly!! Thanks in advance. Here's what i'm trying to accomplish: in my form i have a table with 3 rows (3 input text), in which user can enter values and then clik save. When he clicks the Save button, i'd like to be...
0
1977
by: s_erez | last post by:
Hi, This is a realy tricky one. I have an ASP.NET application where some pages are reading data from a DB and presenting reports. In order for the user to wait while the page is reading data from the DB I am using a DIV with a please wait message which is removed once the page is loaded. In addition I am using a global error handling using...
2
2355
by: rked | last post by:
I get nameSPAN1 is undefined when I place cursor in comments box.. <%@ LANGUAGE="VBScript" %> <% DIM ipAddress ipAddress=Request.Servervariables("REMOTE_HOST") %> <html> <head> <meta http-equiv="Content-Type" content="text/html;
7
3584
by: x muzuo | last post by:
Hi guys, I have got a prob of javascript form validation which just doesnt work with my ASP code. Can any one help me out please. Here is the code: {////<<head> <title>IIBO Submit Page</title> </head> <style type="text/css">
4
3507
by: pshindle | last post by:
DB2 Team - I just downloaded and unzipped the new Fixpack 9 for DB2 ESE V8 for Windows (FP9_WR21350_ESE.exe). I then burned the unzipped Fixpack files to a CD. I proceded to install this Fixpack on a test machine running ESE but encountered a serious error during the install. It started 'copying new files' but then stopped cold and...
23
3245
by: Jason | last post by:
Hi, I was wondering if any could point me to an example or give me ideas on how to dynamically create a form based on a database table? So, I would have a table designed to tell my application to create certain textboxes, labels, and combo boxes? Any ideas would be appreciated. Thanks
1
54484
PEB
by: PEB | last post by:
POSTING GUIDELINES Please follow these guidelines when posting questions Post your question in a relevant forum Do NOT PM questions to individual experts - This is not fair on them and we instruct our experts to ignore any such PMs completely Be sure to give the version of Access that you are working with and the Platform and OS if...
4
2328
by: fatboySudsy | last post by:
Hi, I have constructed a client program that has given me some error codes that i just cannot see. I was wondering if a different set of eyes with much more experience than me could help me out. Here are the error codes and underneath i have listed the program. Thanks in advance for looking. client.c: In function `main': client.c:118:...
0
7916
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7660
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7962
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5498
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5217
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3631
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2101
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1207
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
932
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.