Laravel DB Connection Query takes alias error, table does not exist

Source: Internet
Author: User
  db::table (' topics ')->select (' topics.* ', ' b.username ', ' B.avatar ', ' C.username as Rname ', ' D.cname ')->where (' Topics.is_hidden ', 0)->leftjoin (' Users b ', ' B.uid  ', ' = ', ' Topics.uid ')->leftjoin (' Users c ', ' c.uid ', ' = ', ' Topics.ruid ')->leftjoin (' Nodes d ', ' d.node_id ', ' = ', ' topics.node_id ')->orderby (' ord ', ' desc ')->take ($limit)->get ();  

Error in connection query alias
SQLSTATE[42S02]: Base table or view not found:1146 table ' startbbs.stb_users B ' doesn ' t exist (Sql:select stb_topics . *, stb_b . username , stb_b . avatar , stb_c . username as rname ,. From left stb_d joins on cname stb_topics stb_users b stb_b . uid = stb_topics . uid Left Join stb_users c on stb_c . uid = stb_topics . Left ruid join stb_nodes d on stb_d . node_id = stb_topics . node_id where stb_topics . = is_hidden 0 Ord ER by ord desc limit 20)

Reply content:

  db::table (' topics ')->select (' topics.* ', ' b.username ', ' B.avatar ', ' C.username as Rname ', ' D.cname ')->where (' Topics.is_hidden ', 0)->leftjoin (' Users b ', ' B.uid  ', ' = ', ' Topics.uid ')->leftjoin (' Users c ', ' c.uid ', ' = ', ' Topics.ruid ')->leftjoin (' Nodes d ', ' d.node_id ', ' = ', ' topics.node_id ')->orderby (' ord ', ' desc ')->take ($limit)->get ();  

Error in connection query alias
SQLSTATE[42S02]: Base table or view not found:1146 table ' startbbs.stb_users B ' doesn ' t exist (Sql:select stb_topics . *, stb_b . username , stb_b . avatar , stb_c . username as rname ,. From left stb_d joins on cname stb_topics stb_users b stb_b . uid = stb_topics . uid Left Join stb_users c on stb_c . uid = stb_topics . Left ruid join stb_nodes d on stb_d . node_id = stb_topics . node_id where stb_topics . = is_hidden 0 Ord ER by ord desc limit 20)

The best thing to do is to copy this SQL into the database management tool and see if it's a problem with your construction.

From the SQL you constructed, it is because the alias is prefixed with the table prefix ' STB '

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.