1
How to implement the following SQL query in MySQL
(Select S. Name
From student s, transcript t
Where S. studid = T. studid and T. crscode = 'cs305 ')
Intersect
(Select S. Name
From student s, transcript t
Where S. studid = T. studid and T. crscode = 'cs315 ')
Thank you ~
Solution:
Intersection
Select A. * From
(
Select S. Name
From Student s, transcript t
Where S. studid = T. studid And T. crscode = ' Cs305 '
) As A
Cross Join
(
Select S. Name
From Student s, transcript t
Where S. studid = T. studid And T. crscode = ' Cs315 '
) As B On A. Name = B. Name;
2.
Select * from (
Select distinct col1 from T1 where...
Union all
Select distinct col1 from T1 where...
) As TBL
Group by TBL. col1 having count (*) = 2
3.
Intersection:
Select * From Table1 as a join Table2 as B on A. Name = B. Name
Example:
Table:
Fielda
001
002
003
Table B:
Fielda
001
002
003
004
Ask how to obtain the following result set, that is, the intersection of Rows A and B.
Fielda
001
002
003
Answer: select a. fielda from a inner join B on A. fielda = B. fielda
Difference set:
Not in indicates the difference set
Select * From Table1 where name not in (Select name from table2)