Home > database >  SQL in negative selection problem of multiple correlation
SQL in negative selection problem of multiple correlation

Time:09-20

The one left in the SQL join more where column_name!=value
Results: the main table one, namely, have not reached the desired results, i.e. not filter,
For multiple data corresponding to the one in the more and more individual data by filtering, the remaining no filtering data will produce the corresponding one,
I want to achieve more contained in the data meet the screening, for one, has also been filtering,
A great god, please help solve, besides the use 'in' what good method, make the fastest query,

CodePudding user response:

I use mybatis, because other does not meet the screening data generated in the query more one data instance, so mybatis processing, also produced one data instance, so also can be in mybatis can solve

CodePudding user response:

SELECT * TABLE_A A LEFT JOIN TABLE_B ON b. B=A. * * * * * * WHERE a. * *=? AND b. * *=?
Above, TABLE_A is what you have said, TABLE_B, it is much, b. after ON * * *, * * *=a. is associated logic of A and B, WHERE after, if not satisfied, it will not be displayed,
Your description, I think should be increased after the WHERE content,

CodePudding user response:

refer to the second floor AHUA1001 response:
SELECT * TABLE_A A LEFT JOIN TABLE_B ON b. B * * *=a. * * * WHERE a. * *=? AND b. * *=?
Above, TABLE_A is what you have said, TABLE_B, it is much, b. after ON * * *, * * *=a. is associated logic of A and B, WHERE after, if not satisfied, it will not be displayed,
Your description, I think should be increased after the WHERE the content of the


Such as the department table department staff table employee
All employees under the query and departments:
SELECT * FROM department d LEFT the JOIN the employee ON d.i e d=e.d id;

Query not Tom department staff and departments under the employees:
SELECT * FROM department d LEFT the JOIN the employee ON d.i e d=e.d id WHERE e.n ame!='Tom';

But in the result set or a department 1, mybatis see department 1, will create an instance, I want to get a result, no department 1, only the department 2,

CodePudding user response:

The solution is:
Query contains' Tom 'department id, and then the id filters out when query department,
Check out 'Tom' department: SELECT did the FROM employee WHERE NAME='Tom';
Query sector: SELECT * FROM department d LEFT JOIN the employee ON d.i e d=e.d id WHERE d.i d NOT IN (SELECT e.d id FROM the employee e WHERE e.n ame='Tom');
  • Related