2012-12-14 32 views
0

我有multipe表+不同領域,我嘗試做這樣的事情:指定自定義行值

SELECT 
    `title` as title, 
    `manufacturer`+`model` as content /* I want to achieve this as well */ 
    `type` = 'auto_table' /* custom variable w/ value auto_table to know from where is this data*/ 
    FROM `auto` 
    WHERE `title` LIKE '%bmw%' 
    OR 
    `manufacturer` LIKE '%bmw' 
    OR 
    `other_data` LIKE '%bmw' 
UNION 
    SELECT 
     `title` as title, 
     `content` as content 
     `type` = 'news_page' /* custom variable w/ value news_page to know from where is this data*/ 
     FROM `news` 
     WHERE `title` LIKE '%bmw%' 
     OR 
     `content` LIKE '%bmw' 

我的意思是我要與它的價值時選擇在飛行中添加一行。 另外一個我想兩個字段組合成一個像manufacturer + modeltitle

+0

而且編程問題是...? – KingCrunch

+0

使用'concate':http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_concat – GBD

回答

1

CONCAT (manufacturer, model) as content

0

試試這個:

SELECT 
    title, 
    CONCAT(manufacturer,model) as content 
    'auto_table' as type 
FROM [...] 
0

很難得到你真正之後在做什麼。是否要一次性插入選擇?

INSERT INTO your_table 
SELECT 
    `title` as title, 
    CONCAT(`manufacturer`,' ', `model`) as content /* I want to achieve this as well */ 
    `type` = 'auto_table' /* custom variable w/ value auto_table to know from where is this data*/ 
    FROM `auto` 
    WHERE `title` LIKE '%bmw%' 
    OR 
    `manufacturer` LIKE '%bmw' 
    OR 
    `other_data` LIKE '%bmw' 
UNION 
    SELECT 
     `title` as title, 
     `content` as content 
     `type` = 'news_page' /* custom variable w/ value news_page to know from where is this data*/ 
     FROM `news` 
     WHERE `title` LIKE '%bmw%' 
     OR 
     `content` LIKE '%bmw' 

使用CONCAT來連接值