-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSQLQuery for joins.sql
More file actions
71 lines (55 loc) · 1.43 KB
/
SQLQuery for joins.sql
File metadata and controls
71 lines (55 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
USE dbbooking_Photographers;
GO
--photographer’s details of rates greater than 4.5 ratings
SELECT
P.PhotographerID, P.FName, P.LName, P.Location, PF.Ratings
FROM
Photographer P
JOIN
Portfolio PF ON P.PhotographerID = PF.PhotographerID
WHERE
PF.Ratings > 4.5;
--users with their contact numbers
SELECT
Users.UserID,
Users.FName,
Users.LName,
UserContact.ContactNo
FROM
dbo.Users
JOIN
dbo.UserContact ON Users.UserID = UserContact.UserID;
--all user and their reviews including users who havent written reviews
SELECT
Users.UserID,
Users.FName,
Review.Comment,
Review.ReviewDate
FROM
Users
FULL OUTER JOIN
Review ON Users.UserID = Review.UserID;
--display all photograhpers by firstname
SELECT
Photographer.PhotographerID,
Photographer.FName,
Photographer.LName,
Review.Comment
FROM
dbo.Photographer
LEFT JOIN
dbo.Review ON Photographer.PhotographerID = Review.PhotographerID
ORDER BY
Photographer.FName ASC;
--count how many reviews each photographer has received.
SELECT
Photographer.PhotographerID,
Photographer.FName,
Photographer.LName,
COUNT(*) AS ReviewCount
FROM
dbo.Photographer
JOIN
dbo.Review ON Photographer.PhotographerID = Review.PhotographerID
GROUP BY
Photographer.PhotographerID, Photographer.FName, Photographer.LName;