0

I have a set of 2 tables , what I am trying to achieve is select all from both , and display from which table it was selected + active=1 set from the values taken from table2 (in the first table there is a boolean = active, everything in table2 is active no need for this column there) but as I wrote I still want the data being selected from table2 set as active in result.

I am totally stuck, would really appreciate some help.

CREATE TABLE `table1` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `value` int(11) DEFAULT NULL,
  `active` bool DEFAULT NULL,
)


CREATE TABLE `table2` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `value` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`)
)

1 Answer 1

1
SELECT *, 't1' tableName
FROM table1

UNION ALL

SELECT *, true 'active', 't2' tableName
FROM table2

DEMO

1
  • Wow! Awesome Marcin lots of <3
    – JazzCat
    Mar 21, 2013 at 9:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.