Home > database >  SQL join condition problem about since the connection
SQL join condition problem about since the connection

Time:04-03

SQLZOO of self join problem:

5. The Execute the self join to the and observe that b.s top gives all the places you can get to the from Craiglockhart, without changing routes. Change the query so that it shows the services from Craiglockhart to London Road,

Answer:
SELECT a.com pany, a.n um, a.s top, b.s top
The FROM the route a
JOIN the route ON b (a.com pany=b.com pany AND a.n um=b.n um)
WHERE a.s top=53 AND b.s top=149

Don't understand the point: (a.com pany=b.com pany AND a.n um=b.n um)

Fellow leaders, young girl recently in self-study SQL, then doing the exercises when don't understand why this problem since the connection condition is a.com pany=b.com pany AND a.n um=b.n um, because before I learn all seem to is a join condition is 1, put two condition here is now going to the heavy role?

According to my own understanding is that the self here join join condition if replace a.com pany=b.com pany, can appear a cartesian product, there will be a lot of the same line if the connection is a.com pany=b.com pany AND a.n um=b.n um, company AND num is the same, you can remove the same line?

I have a period of chaos, the expression of Shanghai, have a great god can help me to reassure the ~? Thank you very much!

CodePudding user response:

My guess is that this ROUTE is public transportation ROUTE data table records, record company field is public transport operating companies, such as AAA bus company, BBB bus company; The num is public transportation lines, such as the 123 bus, subway line 8; Stop recording is each public transportation line stops,

So, a.com pany=b.com pany AND a.n um=b.n um is may represent the same operators on the same line, AND then use the WHERE a.s top=53 AND b.s top=149 53 site can query to be used as an starting point, all 149 sites for the finish line,
  • Related