The point is what. They asked me to make a sample of 3 tables:

Student(Table) ID | FIO | Adress | Group Link(Table) IDT | Group | Subject Teacher(Table) ID | FIO | Adress 

As a result of the sample, we should see the following fields:

 Student.FIO | Link.Subject | Teacher.FIO 

Well, I kind of wrote a query:

 SELECT Student.FIO, link.Subject, Teacher.FIO FROM (Student INNER JOIN link ON student.Group = link.Group) INNER JOIN Teacher ON link.IDT = Teacher.ID WHERE (`Student`.`FIO` LIKE '%Pupkin%'); 

Everything is doing fine, then I was told that it was allegedly not invested, make it embedded. What and how crazy I will not apply. Soon will break phpmyadmin . Help me please.

  • Well, in this case, you solved the problem correctly ... <br> But you need to know about nested queries. - Zowie

2 answers 2

And why is there an investment? to slow down or something? Nesting can be applied in different phrases. For example, in the list of selectable fields

 SELECT Student.FIO, link.Subject, (SELECT Teacher.FIO FROM Teacher WHERE Teacher.ID = link.IDT) AS TFIO FROM Student JOIN link ON student.Group = link.Group WHERE Student.FIO LIKE '%Pupkin%' 
  • I've been reading here about nesting and it is really written that it slows down performance. Thank you kind man for help. - Afimida
  • Duh - the nesting should not even be an expert for the expert :) - FoxManiac

Cheto zamudreno everything, so will not work?

 SELECT st.FIO, ln.subject, tch.fio FROM Student st LEFT JOIN Link ln ON st.group=ln.group LEFT JOIN Teacher tch ON ln.IDT=tch.ID WHERE St.FIO LIKE '%Pupkin%' 
  • one
    this is not nesting, or not? just rephrased SELECT - FoxManiac
  • one
    And why nesting, I fully agree with @renegator, queries with nested subqueries are an order of magnitude slower executed. - Timenzzo