· 8 years ago · Jun 21, 2018, 04:16 PM
1CREATE TABLE `saq_question` (
2 `id` smallint(5) unsigned NOT NULL auto_increment,
3 `url_id` varchar(20) NOT NULL,
4 `question` mediumtext,
5 `pci_version` varchar(10) NOT NULL,
6 `qid` varchar(45) NOT NULL,
7 `a` tinyint(1) NOT NULL default '0',
8 `b` tinyint(1) default '0',
9 `c` tinyint(1) default '1',
10 `d` tinyint(1) default '1',
11 `requirement` smallint(5) unsigned NOT NULL default '0',
12 `saq_cat` varchar(10) NOT NULL,
13 `level` int(11) NOT NULL,
14 `show_answer` tinyint(4) NOT NULL default '1',
15 `custom_questions_id` tinyint(4) default NULL,
16 PRIMARY KEY (`id`),
17 KEY `url_id` (`url_id`),
18 KEY `req_version` (`requirement`,`pci_version`)
19) ENGINE=InnoDB AUTO_INCREMENT=248 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC;
20
21
22I have a page that displays a list of questions, a user has the ability to create a custom question . if they have a custom question then that question gets displayed instead of the default question.
23
24My current query displays all the results. But it also displays both the default quesiton and a custom question where it exists. So for wherever a custom question exists i need it to display that one instead of the default.
25
26The difference between a default question and a custom question is that the custom question has a value in the custom_questions_id column.
27
28Here's my query
29
30SELECT q.custom_questions_id,q.qid,q.url_id, q.id, q.question, q.pci_version, q.a, q.b, q.c, q.d,
31q.requirement, q.saq_cat, q.level, q.show_answer, a.id answer_id, a.answer, a.reason from
32saq_question q left join saq_answer a on q.id=a.question_id and (a.profile_id=? or a.profile_id is
33null) where q.requirement=? and q.pci_version=? and q.saq_cat like ? and (q.custom_questions_id=?
34or q.custom_questions_id is null) order by q.url_id