| |

VerySource

 Forgot password?
 Register
Search
View: 1079|Reply: 8

Join query statement

[Copy link]

2

Threads

7

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 Australia

Post time: 2020-3-6 07:00:01
| Show all posts |Read mode
I have 2 tables
Queryname, reportname, path content
Requirement, return reportname is not included in the column of reportname in Table 2. The column in Table 2 is username = xxx.
No matter I use <>, not in will not get the correct result
However, IN, = can get the correct result required to the contrary. . How to do it

SELECT dbo.ReportList. *
FROM dbo.ReportList INNER JOIN
      dbo.UserReport ON dbo.ReportList.ReportName <> dbo.UserReport.ReportName
Reply

Use magic Report

0

Threads

114

Posts

69.00

Credits

Newbie

Rank: 1

Credits
69.00

 China

Post time: 2020-5-21 10:30:01
| Show all posts
SELECT dbo.ReportList. *
FROM dbo.ReportList a,
      dbo.UserReport b where a.ReportName <> b.ReportName
Reply

Use magic Report

0

Threads

88

Posts

55.00

Credits

Newbie

Rank: 1

Credits
55.00

 China

Post time: 2020-5-21 12:00:02
| Show all posts
select reportname, path from ReportList where reportname not in (select reportname from UserReport)
Reply

Use magic Report

0

Threads

28

Posts

25.00

Credits

Newbie

Rank: 1

Credits
25.00

 China

Post time: 2020-5-21 14:00:02
| Show all posts
SELECT dbo.ReportList. *
FROM dbo.ReportList a,
      dbo.UserReport b where isnull (a.ReportName, '') <> isnull (b.ReportName, '')
Reply

Use magic Report

1

Threads

23

Posts

18.00

Credits

Newbie

Rank: 1

Credits
18.00

 China

Post time: 2020-5-21 14:45:01
| Show all posts
select * from ReportList a where not exists (select * from UserReport where ReportName = a.ReportName)
Reply

Use magic Report

0

Threads

211

Posts

108.00

Credits

Newbie

Rank: 1

Credits
108.00

 China

Post time: 2020-5-21 17:00:01
| Show all posts
--try

SELECT dbo.ReportList. *
FROM dbo.ReportList as A
where exists (select 1 from UserReport where ReportName <> A.ReportName)
Reply

Use magic Report

0

Threads

10

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

Post time: 2020-5-21 21:00:01
| Show all posts
The opposite is obtained,
Then you can get what you want with not exists
Reply

Use magic Report

0

Threads

126

Posts

73.00

Credits

Newbie

Rank: 1

Credits
73.00

 China

Post time: 2020-5-22 23:00:01
| Show all posts
SELECT dbo.ReportList. *
FROM dbo.ReportList as A
where A.ReportName NOT IN (select ReportName from UserReport)
Reply

Use magic Report

2

Threads

7

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 Australia

 Author| Post time: 2020-5-27 16:15:01
| Show all posts
Thank you all. It turns out that you need multiple () to solve it. . I'm so stupid. . Tried for a long time
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list