I have tables like this:
Table1 Table2
name1 | link_id name2 | link_id
text 1 text 2
text 2 text 4
And I want to get the result:
name1 name2 link_id
text text 1
text text 2
text text 4
How can i do this?
ADD: Sry, my English is not very good. I have device tables, device_model and device_type with a duplicate counter_set_id field. I want to select fields from counter_set with all counter_set_id values. I need to get values only from counter_set_id fields
Now I have this query:
SELECT `dev`.`counter_set_id`, `mod`.`counter_set_id`, `type`.`counter_set_id`
FROM `device` AS `dev`
LEFT JOIN `device_model` AS `mod` ON `dev`.`device_model_id` = `mod`.`id`
LEFT JOIN `device_type` AS `type` ON `mod`.`device_type_id` = `type`.`id`
WHERE `dev`.`id` = 4;
This returns 3 columns, but I need all the values in one column
This is the final version, I think:
SELECT `dev`.`counter_set_id`
FROM `device` AS `dev` LEFT OUTER JOIN
`device_model` AS `mod` ON `dev`.`device_model_id` = `mod`.`id`
WHERE `dev`.`id` = 4 AND
`dev`.`counter_set_id` IS NOT NULL
UNION
SELECT `mod`.`counter_set_id`
FROM `device_model` AS `mod` LEFT OUTER JOIN
`device` AS `dev` ON `mod`.`id` = `dev`.`device_model_id`
WHERE `mod`.`counter_set_id` IS NOT NULL;
source
share