我有以下查詢,但是這一次返回3行,我想一個行;-)合併多行到一個
SELECT
b_firstname ,value
FROM
cscart_user_profiles
RIGHT JOIN profile_fields_data ON profile_fields_data.object_id = user_profiles.profile_id
WHERE
user_profiles.b_title NOT LIKE ''
AND user_profiles.profile_id = '4252'
AND (
profile_fields_data.field_id ='69'
OR
profile_fields_data.field_id ='73'
OR
profile_fields_data.field_id ='75'
)
...但是這將返回3行:
user1 value
user1 value
user1 value
我想1行:
USER1 value69 user73 value75
我怎樣才能解決這個問題?
下面的表2的數據在哪裏
CREATE TABLE IF NOT EXISTS `cscart_user_profiles` (
`profile_id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
`user_id` mediumint(8) unsigned NOT NULL DEFAULT '0',
`profile_type` char(1) NOT NULL DEFAULT 'P',
`b_title` varchar(32) NOT NULL DEFAULT '',
`b_firstname` varchar(128) NOT NULL DEFAULT '',
`b_lastname` varchar(128) NOT NULL DEFAULT '',
`b_address` varchar(64) NOT NULL DEFAULT '',
`b_address_2` varchar(64) NOT NULL DEFAULT '',
`b_city` varchar(64) NOT NULL DEFAULT '',
`b_county` varchar(32) NOT NULL DEFAULT '',
`b_state` varchar(32) NOT NULL DEFAULT '',
......
PRIMARY KEY (`profile_id`),
KEY `uid_p` (`user_id`,`profile_type`),
KEY `profile_type` (`profile_type`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=0 ;
CREATE TABLE IF NOT EXISTS `cscart_profile_fields_data` (
`object_id` mediumint(8) unsigned NOT NULL DEFAULT '0',
`object_type` char(1) NOT NULL DEFAULT 'U',
`field_id` mediumint(8) unsigned NOT NULL DEFAULT '0',
`value` varchar(255) NOT NULL DEFAULT '0',
PRIMARY KEY (`object_id`,`object_type`,`field_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
考慮發佈您的數據庫架構和示例數據。 – Minesh 2013-02-15 13:30:08
@minesh,你呢? – Bas 2013-02-15 14:11:37