简体   繁体   中英

select multiple values from same column

SELECT b_lastname, b_firstname, cscart_profile_fields_data.value AS VAT
FROM cscart_user_profiles
INNER JOIN cscart_profile_fields_data ON cscart_profile_fields_data.object_id = cscart_user_profiles.user_id
WHERE cscart_profile_fields_data.field_id =64
AND cscart_profile_fields_data.object_type = 'P'

I am using the code above, in order to get values from the cscart_user_profiles table but also from cscart_profile_fields_data table and especially the value field. What i would like to do is get different values from the value field in the same query, just by changing the field_id

If I understand your question:

SELECT b_lastname, b_firstname, cscart_profile_fields_data.value AS VAT
FROM cscart_user_profiles
INNER JOIN cscart_profile_fields_data ON cscart_profile_fields_data.object_id = cscart_user_profiles.user_id
WHERE cscart_profile_fields_data.field_id IN (64, ...)
AND cscart_profile_fields_data.object_type = 'P'

This quere return as many rows as parameters in WHERE IN condition

or:

SELECT b_lastname, b_firstname, GROUP_CONCAT(cscart_profile_fields_data.value SEPARATOR ';') AS VAT
FROM cscart_user_profiles
INNER JOIN cscart_profile_fields_data ON cscart_profile_fields_data.object_id = cscart_user_profiles.user_id
WHERE cscart_profile_fields_data.field_id IN (64, ...)
AND cscart_profile_fields_data.object_type = 'P'
GROUP BY b_lastname, b_firstname

above query return one row with many values in VAT column separated by ; character (like CSV file)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM