将 SQL 语句从 USING 重写为 ON

发布于 2024-10-01 03:14:31 字数 3777 浏览 7 评论 0原文

嘿伙计们。这里遇到麻烦了。必须使用相同 MySQL 和 PHPmyadmin 版本的网络酒店,但反应不同。也许与 MySQL.ini 有关。

我怎样才能将其重写为ON,从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

希望你能在这里帮助我。谢谢。

编辑:

现在我得到了这个,但它显示了 11.700 个结果,它应该只显示 2 个。但这是正确的结果,它们只是循环。

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

数据库表:

    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 ;

Hey guys. Having trouble here. Have to webhotels with same MySQL and PHPmyadmin versions, but reacts different. Mayb something with the MySQL.ini.

How can I rewrite this into ON, from 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

Hope you can help me here.Thank you.

Edit:

Now I got this, but it shows 11.700 results, and it should only show 2. But it is the right results, their just looping.

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

DB Tables:

    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 ;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

め七分饶幸 2024-10-08 03:14:31

我做到了!是的,

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

谢谢大家

I did it! 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

Thanks guys

蒗幽 2024-10-08 03:14:31

您应该使用 INNER JOIN jointablename ON jointablename.join_id = tablename.id,对于这种情况查询将如下所示:

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..

You should use INNER JOIN jointablename ON jointablename.join_id = tablename.id, for this case query will looks like:

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..
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文