0Pricing
Neo4j Graph Database Fundamentals · Ders

WITH ve UNION ile Sorguları Birleştirme

İleri düzey Cypher sorguları için sorgu aşamalarını WITH kullanarak zincirlemeyi ve sonuç kümelerini UNION kullanarak birleştirmeyi öğrenin.

WITH ve UNION ile Sorguları Birleştirme, CoddyKit'te ücretsiz bir Neo4j Graph Database Fundamentals dersidir. Bu, 4 dersinin 4. dersidir. Aşağıdan dersin tamamını ücretsiz okuyabilir, sonra tarayıcıda yerleşik kod editörü ve 7/24 yapay zeka koçu ile uygulamalı olarak pratik yapabilirsin. Bu, Neo4j Graph Database Fundamentals öğrenme yolunun bir parçasıdır ve ilerlemeniz web ve CoddyKit uygulaması arasında senkronize olur. Neo4j Graph Database Fundamentals kursu toplamda 4 dersten oluşur.

Bu dersin bazı bölümleri henüz çevrilmemiş olup İngilizce olarak gösterilmektedir.

Why Chain Query Stages

Complex questions often need several steps: filter, aggregate, then filter again. Cypher uses WITH to pass results from one stage to the next.

Introducing WITH

WITH works like RETURN but feeds its output into the next part of the query instead of ending it.

MATCH (p:Person)-[:FRIEND]->(f)
WITH p, count(f) AS friendCount
WHERE friendCount > 3
RETURN p.name, friendCount;

Filtering After Aggregation

You cannot put aggregate functions in a WHERE directly. Instead, aggregate with WITH, then filter the aggregated value in the following WHERE.

This is the Cypher equivalent of SQL's HAVING.

MATCH (c:City)<-[:LIVES_IN]-(p:Person)
WITH c, count(p) AS population
WHERE population > 1000
RETURN c.name, population;

Carrying Variables Forward

Only variables listed in WITH stay in scope afterward. Anything omitted is dropped, so list everything you still need.

MATCH (p:Person)-[:BOUGHT]->(prod)
WITH p, collect(prod.name) AS products
RETURN p.name, products;

Ordering and Limiting Mid-Query

WITH can include ORDER BY, SKIP, and LIMIT to shape intermediate results before the next stage.

MATCH (p:Person)
WITH p ORDER BY p.age DESC LIMIT 5
MATCH (p)-[:FRIEND]->(f)
RETURN p.name, f.name;

Introducing UNION

UNION combines the results of two queries into one result set. Both sides must return the same column names.

MATCH (p:Person) RETURN p.name AS name
UNION
MATCH (c:Company) RETURN c.name AS name;

UNION vs UNION ALL

UNION removes duplicate rows. UNION ALL keeps every row, including duplicates, and is faster when you know there are none.

MATCH (p:Person) RETURN p.name AS name
UNION ALL
MATCH (c:Company) RETURN c.name AS name;

Combining WITH and UNION

You can aggregate within each side of a UNION using WITH, then merge the summaries. This builds powerful reporting queries.

MATCH (o:Order) WITH 'orders' AS kind, count(o) AS n RETURN kind, n
UNION
MATCH (u:User) WITH 'users' AS kind, count(u) AS n RETURN kind, n;

Multiple WITH Stages

You can chain many WITH clauses to build a pipeline: each stage refines the data further.

MATCH (p:Person)-[:RATED]->(m:Movie)
WITH m, avg(p.rating) AS avgRating
WITH m, avgRating WHERE avgRating > 4
RETURN m.title, avgRating;

Common Pitfalls

Watch out for:

  • Forgetting to carry a needed variable through WITH
  • Mismatched column names across UNION branches
  • Using WITH when a simple WHERE would do

When to Use Each

Use WITH for multi-step pipelines and post-aggregation filtering. Use UNION to stack results from structurally different queries.

Quick Check

Check your understanding of query composition.

Recap

You learned to compose advanced queries:

  • WITH pipes results between stages
  • Filter aggregates after WITH (like HAVING)
  • Only variables in WITH stay in scope
  • UNION merges result sets; UNION ALL keeps duplicates

Sıkça Sorulan Sorular

“WITH ve UNION ile Sorguları Birleştirme” dersi ücretsiz mi?

Evet — “WITH ve UNION ile Sorguları Birleştirme” dersin tüm metni burada web'de ücretsiz olarak okunabilir. Etkileşimli olarak pratik yapmak (yerleşik kod editörü ve 7/24 yapay zeka koçu) ve Neo4j Graph Database Fundamentals kursunun geri kalanını açmak için CoddyKit PRO'ya yükselt. Neo4j Graph Database Fundamentals kursu toplamda 4 dersten oluşur.

“WITH ve UNION ile Sorguları Birleştirme” dersinde ne öğreneceğim?

İleri düzey Cypher sorguları için sorgu aşamalarını WITH kullanarak zincirlemeyi ve sonuç kümelerini UNION kullanarak birleştirmeyi öğrenin. Neo4j Graph Database Fundamentals ile uygulamalı kodu tarayıcıda doğrudan çalıştırarak pratik yaparsın ve 7/24 yapay zeka koçu dersi çalışırken sorularını yanıtlar.

Neo4j Graph Database Fundamentals öğrenmeye başlamak için deneyim gerekli mi?

Önceden deneyim gerekmez. CoddyKit'te Neo4j Graph Database Fundamentals, başlangıçtan ileri seviyeye kadar yapılandırıldığı için buradan başlayabilir veya başından başlayıp kendi hızında ilerleme yapabilirsin. Bu, 4 dersinin 4. dersidir.

“WITH ve UNION ile Sorguları Birleştirme” dersi ne kadar sürer?

Çoğu CoddyKit dersi yaklaşık 5–10 dakika sürer. Her biri kısa ve etkileşimli olduğu için sabit ilerleme yaparsın ve web ile uygulama arasında tam olarak bıraktığın yerden devam edebilirsin.

Bu Neo4j Graph Database Fundamentals dersinde kod yazıp çalıştırabilir miyim?

Evet. Her Neo4j Graph Database Fundamentals dersi yerleşik bir kod editörü içerir, bu sayede tarayıcıda gerçek kod yazıp çalıştırabilir ve anlık yapay zeka geri bildirimi alırsın — yerel kurulum gerekli değildir.

Bu kursun tüm dersleri

  1. Sonuçları Filtreleme ve Sıralama
  2. Toplama ve Projeksiyonlar
  3. Graf Verilerini Güncelleme ve Silme
  4. WITH ve UNION ile Sorguları Birleştirme
← Neo4j Graph Database Fundamentals Sayfasına Dön