English 中文(简体)
• 如何从一个排入另一个表层的浏览中提取数据?
原标题:How to fetch data from row that is indexed to another table row?
  • 时间:2012-05-04 15:31:46
  •  标签:
  • mysql

我的表象是:

.poll_users
(id int(11) NOT NULL AUTO_INCREMENT
name VARCHAR(255) NOT NULL
PRIMARY KEY (id))

.poll_referendum
        (id int(11) NOT NULL AUTO_INCREMENT
        name varchar(255) DEFAULT NULL
        PRIMARY KEY (id))

.poll_questions 
     id int(11) NOT NULL AUTO_INCREMENT
    referendum_id int(11) DEFAULT NULL
    body varchar(255) DEFAULT NULL
    created_at datetime DEFAULT NULL
    updated_at datetime DEFAULT NULL
    PRIMARY KEY (`id`)
    KEY `referendum_id` (`referendum_id`))

.poll_answers 
 `id` int(11) NOT NULL AUTO_INCREMENT
 `vote_id` int(11) DEFAULT  0 
 `question_id` int(11) NOT NULL
 `created_at` datetime DEFAULT NULL
 `updated_at` datetime DEFAULT NULL
 PRIMARY KEY (`id`)
 KEY `vote_id` (`vote_id`)
 KEY `question_id` (`question_id`))

.poll_voting 
    `id` int(11) NOT NULL AUTO_INCREMENT
    `question_id` int(11) NOT NULL DEFAULT  0 
    `answer_id` int(11) NOT NULL DEFAULT  0 
    `user_id` int(11) NOT NULL DEFAULT  0 
    `created_at` datetime DEFAULT NULL
    `updated_at` datetime DEFAULT NULL
    PRIMARY KEY (`id`)
    KEY `question_id` (`question_id`)
    KEY `answer_id` (`answer_id`)
    KEY `user_id` (`user_id`))

.vote_types 
    `id` int(11) NOT NULL AUTO_INCREMENT
    `type` varchar(255) DEFAULT NULL
    PRIMARY KEY (`id`))

我怎么能够选择投票类型——类型表,与适当的问答和调查相对应?

I have tried: SELECT vote_id FROM surveys.poll_answers WHERE question_id = 1; but this gives me: enter image description here

and 1,2 are indexes to the vote type text SELECT * FROMsurveys.vote_types WHEREid=1 In poll_answers table I keep indexes what vote types are assigned to questions and questions are assigned to proper referendums in poll_referendum table so how do I fetch those vote types corresponing to proper question and survey like

SELECT vote_id indexes from poll_answers table and they index to vote_types where are stored vote types in text and those vote_types corresponds to proper questions that are stored in poll_questions and referendums that are stored in poll_referendum ? 

感谢您的帮助

问题回答

我不相信。 也许你正在谈论桌子。

SELECT 
           v.*
      FROM poll_answers AS a
      INNER JOIN poll_voting AS v ON (v.id=a.vote_id)
      WHERE a.question_id = 1;




相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签