skip to Main Content

So, i have two tables

fahrlehrer(id_f,first name,last name)

and

fahrschueler(id,first name, last name,id_f).

I have the last name of a column in fahrlehrer.
now my task is to show the first name and last name of all fahrschueler that have the FK of the the given name

my idea so far is:

select fahrschueler.nachname, fahrschueler.vorname 
from fahrschueler
join fahrlehrer
on fahrschueler.fahrlehrernr = (select fahrlehrernr from fahrlehrer where nachname = "Blechle");

My guess is that the brackets are set wrong as im not sure of the syntax, glad the learn the right syntax

if there is something unclear lmk

edit:
i dont have datas, my task says: give out all first and last names of fahrschueler if their fahrleher’s name is "Blechle"

the output shouldnt be a help since the output is only the names

2

Answers


  1. You can do it using inner join to join your tables into one as follows :

    select t1.nachname, t1.vorname 
    from fahrschueler t1
    join fahrlehrer t2 on t1.id_f = t2.id_f
    where t2.nachname = 'Blechle'
    
    Login or Signup to reply.
  2. select fahrschueler.nachname, fahrschueler.vorname 
    from fahrschueler
        join fahrlehrer on fahrschueler.id_f = fahrlehrer.id_f
    WHERE fahrlehrer.nachname = 'Blechle'
    

    Join the 2 tables using the id_f and its alway best to use single quotes in a query around a string.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search