我一直在尝试将Slick添加到我的应用程序中,一切都很顺利,直到我不得不进行左连接。下面是我试图生成的SQL查询:
SELECT i.id,i.category_id,iab.aspect_ids FROM items i LEFT JOIN item_aspects_binary iab ON i.id=iab.item_id WHERE i.id = 380292547708
左侧连接由左侧表的主ID过滤。这是我用来生成Slick Query的理解:
val q = for {
(i, a) <- items leftJoin itemAspects on (_.id === _.itemId) if (i.id === id)
} yield (i.id, i.category, a.aspectIds)
然后生成以下SQL查询:
select x2.x3, x2.x4, x5.x6 from (select x7.`id` as x3, x7.`category_id` as x4 from `items` x7) x2 left outer join (select x8.`item_id` as x9, x8.`aspect_ids` as x6 from `item_aspects_binary` x8) x5 on x2.x3 = x5.x9 where x2.x3 = 380292547708
但是,这会出现以下错误:“您的SQL语法有错误;请查看与您的MySQL服务器版本对应的手册,以便在'select x2。id
附近使用正确的语法。{2}。来自category_id
x2的items
,x3.x4,(在第3行选择x2。id
为x5 f'
我错过了什么吗?
另外,为什么会生成子查询?