can not join another query #388

Closed
opened 2016-05-05 09:09:35 +00:00 by localvar · 4 comments
localvar commented 2016-05-05 09:09:35 +00:00 (Migrated from github.com)

I'm using mysql driver and need to join the result of another query, for example:

tran.Join("LEFT", "(SELECT template_id Id, COUNT(1) Heat FROM Ad GROUP BY template_id) AS h", "t.TEMPLATE_ID = h.Id")

but xorm generate wrong sql by add ` to the sub query

This issue may also affect the 'In' function

I'm using mysql driver and need to join the result of another query, for example: ``` tran.Join("LEFT", "(SELECT template_id Id, COUNT(1) Heat FROM Ad GROUP BY template_id) AS h", "t.TEMPLATE_ID = h.Id") ``` but xorm generate wrong sql by add ` to the sub query This issue may also affect the 'In' function

Hi,
Join function is not designed to support query join. I will test if we can change it to support.

Hi, `Join` function is not designed to support query join. I will test if we can change it to support.
localvar commented 2016-05-06 01:03:28 +00:00 (Migrated from github.com)

If cannot make Join and In to support query, is it possible to add new functions like: JoinQuery and InQuery?

If cannot make `Join` and `In` to support query, is it possible to add new functions like: `JoinQuery` and `InQuery`?

It could be considered.

It could be considered.
ericchan77 commented 2019-05-21 15:47:11 +00:00 (Migrated from github.com)

遇到了同样的情况,当 LEFT OUTER JOIN 的时候:

LEFT OUTER JOIN `(SELECT pkg_id, COUNT(1) AS count FROM versions WHERE deleted_at = '0001-01-01 00:00:00' GROUP BY (pkg_id))` AS `v` 

的时候,就会报

Incorrect table name '(SELECT pkg_id, COUNT(1) AS count FROM versions WHERE deleted_at = '0001-01-01 00:00:00' GR'

请问现在有什么解决方案么?
@lunny

遇到了同样的情况,当 `LEFT OUTER JOIN` 的时候: ``` LEFT OUTER JOIN `(SELECT pkg_id, COUNT(1) AS count FROM versions WHERE deleted_at = '0001-01-01 00:00:00' GROUP BY (pkg_id))` AS `v` ``` 的时候,就会报 ``` Incorrect table name '(SELECT pkg_id, COUNT(1) AS count FROM versions WHERE deleted_at = '0001-01-01 00:00:00' GR' ``` 请问现在有什么解决方案么? @lunny
lunny closed this issue 2020-02-21 02:44:05 +00:00
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: xorm/xorm#388
No description provided.