sql - MYSQL | select inverse value between 2 tables -


i select records table have different values one.

table 1.

+--------+-------+ | userid | tagid | +--------+-------+ |      1 |     2 | |      1 |     3 | |      1 |     4 | +--------+-------+ 

table 2.

+---------+-------+ | chaname | tagid | +---------+-------+ | hello   |     1 | | how     |     2 | |     |     3 | |     |     4 | | today   |     5 | | guys    |     6 | | ?       |     7 | +---------+-------+ 

and suppose be

+--------+-------+---------+ | userid | tagid | chaname | +--------+-------+---------+ |      1 |     1 | hello   | |      1 |     5 | today   | |      1 |     6 | guys    | |      1 |     7 | ?       | +--------+-------+---------+ 

it looks simple can't find way solve it.
thank of answers <3

ps. btw i've tried use ' not in ' got error

unrecognized keyword. (near "not in" @ position 92) 

to output, need use outer join. left join give records left table table2 , matching records right table table1. means null records in table1 doesn't exist in table2. can use property in where clause expected records.

also cannot decide on userid on records in table2. if want hardcode them 1, use select 1 userid, ... in select clause.

sqlfiddle demo

select t2.tagid,t2.chaname  table2 t2 left join table1 t1 on t1.tagid=t2.tagid t1.tagid null 

Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -