SELECT roomname, usercount, userlimit, topic, extra
FROM TableA
UNION
SELECT roomname, usercount, userlimit, topic, extra
FROM TableA
By default, a union query in MySQL does 'distinct' and eliminates duplicate rows (aka UNION DISTINCT
). If you wanted to get the duplicate rows, then you'd do UNION ALL
instead.
ok, since you've now said that only the roomname is common/duplicated between the tables, how about something like:
select tableA.*, tableB.*
from tableA
join tableB on tableA.roomname = tableB.roomname
where (tableA.usercount <> tableB.usercount) or (tableA.userlimit <> tableB.userlimit)
or (tableA.topic <> tableB.topic) or (tableA.extra <> tableB.extra)
That'd bring back all rows from both tables where they share the same roomname, but have differences in one or more of the other fields. If you want to show only exact duplicates on those fields, change the <>
to =
.
mod part 2
select tableB.*
from tableB
left join tableA on tableA.roomname = tableB.roomname
where tableA.roomname is null
this will return all records from table B where the roomname field does NOT have a match in table A
After OP's updated explanation:
SELECT roomname, usercount, userlimit, topic, extra
FROM TableA
UNION ALL
SELECT roomname, usercount, userlimit, topic, extra
FROM TableB
WHERE roomname NOT IN
( SELECT roomname FROM TableA )