[英]Assign a value to a field on SELECT statement
im not sure if im doing well with this field calendar.type_event = NULL . 我不确定即时通讯是否可以很好地处理calendar.type_event = NULL 。 Now works well to me because I need to differentiate the second SELECT as a third type.
现在对我来说效果很好,因为我需要将第二个SELECT区分为第三个类型。
I want to do something like calendar.type_event = 'shared_event' to differentiate it. 我想做一些类似calendar.type_event ='shared_event'的事情。 But returns a 0, with NULL returns nothing.
但是返回0,带NULL不返回任何内容。 This is not the problem only I need to know if I can assign my own value: 'shared_event'.
这不是问题,仅是我需要知道是否可以分配自己的值:“ shared_event”。
Thanks a lot 非常感谢
The entire query is: 整个查询是:
(SELECT
id, type_event
FROM calendar
WHERE user_id = '.$user_id.'
)
UNION
(SELECT
calendar.id, calendar.type_event = NULL
FROM calendar
RIGHT JOIN avisos ON avisos.app_id = calendar.id
WHERE avisos.user_destiny_id = '.$user_id.'
)
ORDER BY fecha_evento ASC
You should be able to do something like this: 您应该能够执行以下操作:
(SELECT
id, type_event
FROM calendar
WHERE user_id = '.$user_id.'
)
UNION
(SELECT
calendar.id, "shared_event"
FROM calendar
RIGHT JOIN avisos ON avisos.app_id = calendar.id
WHERE avisos.user_destiny_id = '.$user_id.'
)
ORDER BY fecha_evento ASC
I need to know if I can assign my own value:
'shared_event'
.我需要知道是否可以分配自己的值:
'shared_event'
。
Yes, you can. 是的你可以。 In place of column
calendar.type_event
just use literal 'shared_event'
代替列
calendar.type_event
只需使用文字'shared_event'
Example : 范例 :
SELECT
calendar.id, 'shared_event'
FROM calendar
RIGHT JOIN avisos ON avisos.app_id = calendar.id
WHERE avisos.user_destiny_id = '.$user_id.'
I think this is what you are looking for: 我认为这是您要寻找的:
(SELECT
id, type_event
FROM calendar
WHERE user_id = '.$user_id.'
)
UNION
(SELECT
calendar.id, '' type_event
FROM calendar
RIGHT JOIN avisos ON avisos.app_id = calendar.id
WHERE avisos.user_destiny_id = '.$user_id.'
)
ORDER BY fecha_evento ASC
In the second query, type_event
field will contain null values. 在第二个查询中,
type_event
字段将包含空值。 If the type_event
field is a numeric field, you can put 0
(ZERO) instead of ''
(empty single quotes/string). 如果
type_event
字段是数字字段,则可以放置0
(零)而不是''
(空单引号/字符串)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.