0

这是我的查询:

SELECT m_title `title` from members UNION select n_title `title` FROM news

尽管下一个查询成功,但此 sql 查询无明显原因失败:

SELECT id from members UNION select n_id `title` FROM news

可能是什么问题呢?

成员:

id  int(11)         No  None    AUTO_INCREMENT    Change      Drop   More 
 2  member_id   int(150)            No  None          Change      Drop   More 
 3  m_title varchar(200)    utf8_unicode_ci     Yes NULL          Change      Drop   More 
 4  txtshortdetails text    utf8_unicode_ci     No  None          Change      Drop   More 
 5  txtfulldetails  text    utf8_unicode_ci     No  None          Change      Drop   More 
 6  video_src   varchar(200)    utf8_unicode_ci     No  None          Change      Drop   More 
 7  m_order int(11)         No  None          Change      Drop   More 
 8  m_cat   int(11)         No  None          Change      Drop   More 
 9  m_date  datetime            No  None          Change      Drop   More 
 10 m_change_date   date            No  None          Change      Drop   More

消息:

n_id    int(10)         No  None    AUTO_INCREMENT    Change      Drop   More 
 2  n_title varchar(200)    utf8_general_ci     Yes NULL          Change      Drop   More 
 3  n_details   text    utf8_general_ci     Yes NULL          Change      Drop   More 
 4  n_pic   varchar(200)    utf8_general_ci     Yes NULL          Change      Drop   More 
 5  n_order int(11)         No  None          Change      Drop   More 
 6  n_date  date            Yes NULL          Change      Drop   More 
4

2 回答 2

0

谢谢大家的帮助。
问题出在两列的不同排序规则中。
第一个有:“utf8_general_ci”
,第二个有:“utf8_unicode_ci”
我让它们一样

于 2013-01-04T19:03:12.200 回答
0

试一试,给出AS关键字:

如果我错了,请纠正我。

SELECT `m_title` AS `title` FROM `members`
UNION
SELECT `n_title` AS `title` FROM `news`

并确保列m_titlen_title存在于各自的表中。

于 2013-01-04T06:04:03.427 回答