【问题标题】:Laravel 5 SQLSTATE[42S22]: Column not foundLaravel 5 SQLSTATE [42S22]:找不到列
【发布时间】:2015-08-10 23:55:34
【问题描述】:

我正在做一些连接并尝试获取数据。我的查询生成器是:

$datasource = DB::table('vehicles')->join('brands', 'vehicles.brand_id', '=', 'brands.id')->join('sections', 'vehicles.section_id', '=', 'sections.id')->select('vehicles.*, vehicles.id AS vid');

但我收到此错误:

SQLSTATE[42S22]:未找到列:1054 未知列 'vehicles.model,' in 'field list' (SQL: select vehicles.model, as AS 来自vehicles 内部连接brandsvehicles.brand_id = brands.id 内部连接 ​​sections vehicles.section_id = sections.id 限制 4 偏移量 0) 行 620

我做错了什么?

【问题讨论】:

    标签: php sql laravel join query-builder


    【解决方案1】:

    您应该使用selectRaw() 而不是select()

    ->selectRaw('vehicles.*, vehicles.id AS vid');
    

    阅读有关原始表达式的更多信息:http://laravel.com/docs/5.0/queries#raw-expressions

    【讨论】:

      猜你喜欢
      • 2020-10-02
      • 2016-01-06
      • 2018-10-20
      • 1970-01-01
      • 2020-07-26
      • 2018-02-21
      • 2015-12-08
      • 2018-11-02
      相关资源
      最近更新 更多