Holy wow, that's a lot of fish.
Fortunately, we've got a lot
of animals that eat fish.
We talked about that
briefly in lesson one, but
now we can put together
an actual query to find them.
See if we can put it together
without looking back there.
Trouble is, the animals table tells
us nothing about what each individual
animal eats, and the diet table
doesn't list any individual animals.
It only lists their species.
Wait a minute though.
That species column is
in both of those tables.
That means it must be join time.
So, if we join animals against diet,
we should be to get the answer
that we're looking for.
Now, we saw one syntax for
joins in lesson one, but
it turns out there's also
a shortcut syntax we can use here.
The shortcut syntax won't actually use
the word join when it lists the joined
tables, but this form is actually
probably more common in real code.
If we want to join two tables to match
up rows where the column target in
table T equals the column match in
table S, we can do it like this.
So on the next page,
write a query to answer this problem.
You can use either kind of join,
but your query should only
return the name column,
not the species or the word fish itself.
.يا إلهي؟ يوجد الكثير من السمك
ولكن للأسف، لدينا الكثير من الحيوانات
.التي تتغذى على السمك
لقد تحدثنا عن ذلك بإيجاز
،في الدرس الأول
ولكن الآن يمكننا تكوين
.استعلام فعلي للبحث عنها
فلنرَ إذا كان بإمكاننا تكوينه
.دون الرجوع إلى هناك
المشكلة هي أن جدول الحيوانات
لا يخبرنا بما يأكل
كل حيوان، كما لا يُدرج
.جدول الغذاء أيًّا من الحيوانات على حدا
.فهو يُدرج أنواعها فقط
.تمهل لحظة
عمود "الأنواع" ذلك
.موجود في كلا الجدولين
."ما يعني أنه قد حان "وقت الدمج
،حسنًا، إذا وضعنا الحيوانات مقابل الغذاء
فلابد لنا من العثور على الإجابة
.التي نبحث عنها
حتى الآن، أطلعنا على بناء جملة
،واحد لعمليات الدمج في الدرس الأول
ولكن اتضح أن هناك بناء جملة
.مختصر يمكننا استخدامه هنا
لن يستخدم بناء الجملة المختصر كلمة join
،فعليًا عند إدراجها الجداول المدمجة
ولكن هذا النموذج قد يكون أكثر شيوعًا فعلاً
.في التعليمة البرمجية الحقيقية
إذا أردنا أن ندمج جدولين
لمطابقة الصفوف حيث العمود target
،في الجدول T يساوي العمود match في الجدول S
يمكننا فعل ذلك على هذا النحو.
في الصفحة التالية
.اكتب استعلامًا لحل هذه المشكلة
،يمكنك استخدام أي نوع دمج
ولكن ينبغي أن يُرجع استعلامك
"اسم العمود فقط وليس "الأنواع
.أو كلمة "سمك" نفسها
Caramba, é muito peixe.
Felizmente, temos muitos
animais que comem peixe.
Falamos sobre isso
brevemente na lição um, mas
agora podemos criar
uma consulta real para encontrá-los.
Veja se podemos criar essa consulta
sem olhar lá atrás.
O problema é que a tabela de animais não
nos diz nada sobre o que cada animal individual
come, e a tabela de dieta
não lista quaisquer animais individuais.
Ela lista apenas suas espécies.
Espere um minuto.
Essa coluna espécie está
em ambas as tabelas.
Isso significa que deve ser a hora de usar join.
Se unirmos animais com dieta,
devemos receber a resposta
que estamos procurando.
Agora, vimos uma sintaxe para
joins na lição um, mas
parece que também existe
uma sintaxe de atalho que podemos usar aqui.
A sintaxe de atalho não usará realmente
a palavra join ao listar as tabelas
unidas, mas esse formato é de fato
mais comum no código real.
Se quisermos juntar duas tabelas para comparar
linhas onde o destino da coluna na
tabela T seja igual à coluna correspondente na
tabela S, podemos fazer dessa forma.
Na próxima página,
escreva uma consulta para responder a esse problema.
Você pode usar qualquer tipo de join,
mas a sua consulta retorna apenas
a coluna nome,
não a espécie ou a palavra peixe em si.
哇 这么多鱼
幸运的是 我们有很多动物都是吃鱼的
我们在第一课中做了简单讨论
但现在我们可以汇总成一个查询 把它们找出来
看看我们不往前查阅的情况下 能不能把它汇总在一起
麻烦的是 动物表格没告诉我们
每个动物吃什么 饮食表格没有列出单个动物
它只列出了它们的物种
等等
这两个表格里都有物种列
这表示它一定是连接时间
因此 如果我们针对饮食连接动物
我们应该能够得到我们想要的答案
我们在第一课中见过一条用于连接的语法
但这里我们还可以使用一个快捷语法
这个快捷语法在列出连接的表格时 实际上不会使用
join 这个语句 但这种形式在实际的代码中或许更加常见
如果我们想要连接两个表格对行进行匹配 其中表格 T 中的
目标列等于表格 S 中相匹配的列 我们可以这样做
好 在下一页写下一条查询 解答这个问题
你可以使用任何一种连接 但你的查询
只能返回名字列 而不是物种或鱼这个词