Search code examples
mysqlexcelexport-to-excel

MYSQL export Value and NOT ID


I have a MYSQL database table called 'wp_quotes' with a field that contains a column called 'media' like below.

'wp_quotes' table

'media' - this column shows '1' or '2' (the ID number) depending on what the user has selected on the form.

I have another table called 'wp_quote_forms_fields_values' that assigns this ID a value - either 'CD' or 'DVD'

'wp_quote_forms_fields_values' table

ID 1 has value of 'CD'

ID 2 has value of 'DVD'

When i run a query (to export a file), how can i get the media column to show 'CD' or 'DVD' instead of '1' or '2'.


Solution

  • You would need to join to the table that has the descriptions, like so:

    SELECT a.ID,a.time,a.quote,b.value as MediaDesc,a.quantity,
    c.value As PackDesc,a.username,
    a.email,a.company,a.contact_number,a.found_us‌​,a.additional_info 
    FROM wp_quotes a
    INNER JOIN wp_quote_forms_fields_values b ON b.ID = a.media
    INNER JOIN wp_quote_forms_fields_values c ON c.ID = a.pack