2010-11-05 17 views
0

Hé les gars. Avoir des problèmes ici. Avoir des webhotels avec les mêmes versions de MySQL et PHPmyadmin, mais réagit différemment. Mayb quelque chose avec le MySQL.ini.Réécrivez l'instruction SQL de USING à ON

Comment puis-je réécrire ceci sur ON, à partir de Using.

SELECT wiederquist_elearn_question.idelearn_question AS idelearn_question, idelearn_answer, idelearn_user, name, email, address, zip, city, phone, extra, user_created_time, newsletter, answertime, title, description, illustration, answertext, correct 
FROM wiederquist_elearn_user 
INNER JOIN wiederquist_elearn_question_answered 
USING (idelearn_user) 
INNER JOIN wiederquist_elearn_question 
USING (idelearn_question) 
INNER JOIN wiederquist_elearn_answer 
USING (idelearn_answer) 
WHERE name IS NOT NULL 
AND idelearn =1 

J'espère que vous pouvez m'aider ici.Merci.

Edit:

Maintenant, j'ai eu, mais il montre 11.700 résultats, et il ne devrait montrer 2. Mais ce sont les bons résultats, leur juste boucle.

SELECT wiederquist_elearn_question.idelearn_question AS idelearn_question, name, email, address, zip, city, phone, extra, user_created_time, newsletter, answertime, title, description, illustration, answertext, correct 
FROM wiederquist_elearn_user 
INNER JOIN wiederquist_elearn_question_answered ON wiederquist_elearn_question_answered.idelearn_user 
INNER JOIN wiederquist_elearn_question ON wiederquist_elearn_question.idelearn_question 
INNER JOIN wiederquist_elearn_answer ON wiederquist_elearn_answer.idelearn_answer 
WHERE name IS NOT NULL 
AND idelearn =1 

Tables DB:

CREATE TABLE `wiederquist_elearn` (
    `ideLearn` int(11) unsigned NOT NULL auto_increment COMMENT 'id', 
    `name` varchar(250) default 'uden navn' COMMENT '''Kursus nav', 
    `correctRequired` int(1) default '0' COMMENT '''Korrekt svar påkrævet for at fortsætt', 
    `successNumber` int(11) default '0' COMMENT '''Antal korrekte svar krævet for "bestået', 
    `displayMode` varchar(45) default 'single' COMMENT '''Ved systemets opstart, enkeltvisning eller listevisnin', 
    `repeatable` int(1) default '0' COMMENT 'Kan kurset gentages', 
    `learning` int(1) default '0', 
    `mandatory` int(1) default '0', 
    `errorMessage` text, 
    PRIMARY KEY (`ideLearn`) 
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ; 

CREATE TABLE `wiederquist_elearn_answer` (
    `idelearn_answer` int(10) unsigned NOT NULL auto_increment, 
    `answertext` text, 
    `correct` int(1) default NULL, 
    `idelearn_question` int(10) unsigned default NULL, 
    `order` int(10) unsigned default NULL, 
    `correctText` text, 
    PRIMARY KEY (`idelearn_answer`) 
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=5 ; 

CREATE TABLE `wiederquist_elearn_question` (
    `idelearn_question` int(10) unsigned NOT NULL auto_increment, 
    `title` text, 
    `description` text, 
    `idelearn` int(10) unsigned default NULL, 
    `illustration` varchar(150) default 'dummy.jpg', 
    PRIMARY KEY (`idelearn_question`) 
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ; 

CREATE TABLE `wiederquist_elearn_question_answered` (
    `idelearn_question_answered` int(10) unsigned NOT NULL auto_increment, 
    `idelearn_user` int(10) unsigned default NULL, 
    `idelearn_question` int(10) unsigned default NULL, 
    `idelearn_answer` int(10) unsigned default NULL, 
    `answertime` timestamp NULL default CURRENT_TIMESTAMP, 
    PRIMARY KEY (`idelearn_question_answered`) 
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ; 

CREATE TABLE `wiederquist_elearn_user` (
    `idelearn_user` int(10) unsigned NOT NULL auto_increment, 
    `name` varchar(250) default NULL, 
    `email` varchar(250) default NULL, 
    `address` varchar(200) default NULL, 
    `zip` int(4) default NULL, 
    `city` varchar(90) default NULL, 
    `phone` varchar(45) default NULL, 
    `extra` varchar(250) default NULL, 
    `user_created_time` timestamp NULL default CURRENT_TIMESTAMP, 
    `newsletter` int(1) default NULL, 
    PRIMARY KEY (`idelearn_user`) 
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ; 
+0

peuvent vous coller les tables et les relations db connexes? – yoda

Répondre

0

Vous devez utiliser INNER JOIN jointablename SUR jointablename.join_id = tablename.id, pour ce cas requête ressemble à:

SELECT weq.idelearn_question AS idelearn_question, idelearn_answer, weu.idelearn_user 
as idelearn_uder, name, email, address, zip, city, phone, extra, user_created_time, 
newsletter, answertime, title, description, illustration, answertext, correct 
    FROM wiederquist_elearn_user AS weu 
     INNER JOIN wiederquist_elearn_question_answered AS weqa 
      ON weu.idelearn_user = weu.idelearn_user 
     INNER JOIN wiederquist_elearn_question AS weq 
      ON weq.idelearn_question = (table your need to join).idelearn_question 
and so on.. 
+0

Pouvez-vous me donner un exemple de travail. Vraiment besoin d'apprendre ça. J'ai essayé d'insérer le nom de la table que je devais rejoindre sans succès. – Holsteinkaa

+0

Je ne connais pas la structure des tables que vous utilisez, donc je peux écrire une mauvaise clause ON. – qnikst

1

Je l'ai fait ! yay

SELECT wiederquist_elearn_question.idelearn_question AS idelearn_question, wiederquist_elearn_answer.idelearn_answer, wiederquist_elearn_user.idelearn_user, name, email, address, zip, city, phone, extra, user_created_time, newsletter, answertime, title, description, illustration, answertext, correct 
FROM wiederquist_elearn_user 
INNER JOIN wiederquist_elearn_question_answered 
USING (idelearn_user) 
INNER JOIN wiederquist_elearn_question 
USING (idelearn_question) 
INNER JOIN wiederquist_elearn_answer ON wiederquist_elearn_answer.idelearn_answer = wiederquist_elearn_question_answered.idelearn_answer 
WHERE name IS NOT NULL and idelearn = 1 

Merci les gars

+0

je vois encore en utilisant et pls, pls apprendre à alias !! (http://pastie.org/1274615) –

+0

Ensuite, c'était l'alias qui l'a gâché. Bizarre comment les serveurs differnet peuvent interpréter différemment. – Holsteinkaa

+0

J'espère que mon exemple simple le rendra plus clair pour vous. J'utilise habituellement la première lettre de la table pour un alias si possible si les clients c, dans votre cas avec vos noms de table longues font quelque chose comme wiederquist_elearn_question_answered comme weqa, wiederquist_elearn_question comme weq etc ... –