SQL Self JOIN

The SQL Self JOIN syntax

The general syntax is:

  1. SELECT columnnames
  2. FROM tablename T1 JOIN tablename T2
  3. WHERE condition

T1 and T2 are different table aliases for the same table


 

SQL Self JOIN Examples

Problem: Match customers that are from the same city and country

  1. SELECT B.FirstName AS FirstName1, B.LastName AS LastName1,
  2. A.FirstName AS FirstName2, A.LastName AS LastName2,
  3. B.City, B.Country
  4. FROM Customer A, Customer B
  5. WHERE A.Id <> B.Id
  6. AND A.City = B.City
  7. AND A.Country = B.Country
  8. ORDER BY A.Country

A and B are aliases for the same Customer table.
Results: 88 records

FirstName1 LastName1 FirstName2 LastName2 City Country
Patricio Simpson Yvonne Moncada Buenos Aires Argentina
Patricio Simpson Sergio Gutiérrez Buenos Aires Argentina
Yvonne Moncada Patricio Simpson Buenos Aires Argentina
Yvonne Moncada Sergio Gutiérrez Buenos Aires Argentina
Sergio Gutiérrez Patricio Simpson Buenos Aires Argentina
Sergio Gutiérrez Yvonne Moncada Buenos Aires Argentina
Anabela Domingues Lúcia Carvalho Sao Paulo Brazil
Anabela Domingues Aria Cruz Sao Paulo Brazil
Anabela Domingues Pedro Afonso Sao Paulo Brazil
Bernardo Batista Janete Limeira Rio de Janeiro Brazil
Bernardo Batista Mario Pontes Rio de Janeiro Brazil
Lúcia Carvalho Anabela Domingues Sao Paulo Brazil
Lúcia Carvalho Aria Cruz Sao Paulo Brazil
Lúcia Carvalho Pedro Afonso Sao Paulo Brazil
Janete Limeira Bernardo Batista Rio de Janeiro Brazil
Janete Limeira Mario Pontes Rio de Janeiro Brazil
Aria Cruz Anabela Domingues Sao Paulo Brazil
Aria Cruz Lúcia Carvalho Sao Paulo Brazil
Aria Cruz Pedro Afonso Sao Paulo Brazil
Mario Pontes Bernardo Batista Rio de Janeiro Brazil
Mario Pontes Janete Limeira Rio de Janeiro Brazil
Pedro Afonso Anabela Domingues Sao Paulo Brazil
Pedro Afonso Lúcia Carvalho Sao Paulo Brazil
Pedro Afonso Aria Cruz Sao Paulo Brazil
Dominique Perrier Marie Bertrand Paris France
Marie Bertrand Dominique Perrier Paris France
Janine Labrune Carine Schmitt Nantes France
Carine Schmitt Janine Labrune Nantes France

Comments (125)

  1. Pingback: mix canzoni estate 2021

  2. Pingback: nam mo thay di hoc

  3. Pingback: tropical house mix 2020

  4. Pingback: Tyson vs Jones jr live stream online

  5. Pingback: lợn đẻ

  6. Pingback: mơ thấy tóc bạc

  7. Pingback: affordable SEO services in Canada. 8. Search engine optimization services in Canada

  8. Pingback: vps server

  9. Pingback: dumps and cvv for sale

  10. Pingback: nằm mơ thấy phật bà quan âm

  11. Pingback: mơ thấy chim bồ câu đánh con gì

  12. Pingback: nằm mơ thấy hoa sen

  13. Pingback: housing market

  14. Pingback: con ngựa số mấy

  15. Pingback: mơ đi xem bói đánh con gì

  16. Pingback: con ong la so may

  17. Pingback: why not look here

  18. Pingback: health insurance

  19. Pingback: buy dumps with pin

  20. Pingback: rolex submariner pr16233bbl black dial mens automatic 41mm

  21. Pingback: dewajitu

  22. Pingback: Pax Era Pods

  23. Pingback: mspy review

  24. Pingback: kejuqq

  25. Pingback: relx

  26. Pingback: ดูบอล

  27. Pingback: diamond painting

  28. Pingback: sagame

  29. Pingback: kardinal stick

  30. Pingback: gui hang di my

  31. Pingback: Krypto tauschen

  32. Pingback: Speedpaste bestellen

  33. Pingback: arvest central mortgage co

  34. Pingback: exchange online plan 2

  35. Pingback: bulut depolama,bulut,yedekleme,ücretsiz bulut hizmeti,en iyi bulut şirketi,en iyi bulut firması,bulut depolama fiyatı,en ucuz bulut depolama,en iyi bulut depolama hangisi,en iyi bulut depolama,bulut arşivleme sistemi,online yedekleme,bulut yedekleme

  36. Pingback: microsoft exchange hosting plan

  37. Pingback: it danışmanlık sözleşmesi

  38. Pingback: dump shop

  39. Pingback: it danışmanlık sözleşmesi

  40. Pingback: HP Server Teknik Servis

  41. Pingback: Server Teknik Servis

  42. Pingback: dumps and tracks

  43. Pingback: world market link

  44. Pingback: Buy Cocaine Online

  45. Pingback: gout de diamants

  46. Pingback: sbobet

  47. Pingback: สโบเบ็ต

  48. 응답

    Okul Testleri İlkokul, Ortaokul ve Lise kademelerinde müfredata uygun testler hazırlamaktadır. Tamamen öğrenci odaklı testler ile öğrenciler derslerde öğrenmiş olduklarını okul testleri sayesinde tekrar edebilir ve öğrendiklerini pekiştirebilir. Kazanım kavrama testlerine uygun ve güncel müfredata dayalıdır.

  49. 응답
  50. 응답
  51. 응답
  52. 응답
  53. 응답
  54. 응답
  55. 응답
  56. 응답
  57. 응답
  58. 응답
  59. 응답
  60. 응답
  61. 응답
  62. 응답
  63. 응답
  64. 응답
  65. 응답
  66. 응답
  67. 응답
  68. 응답
  69. 응답
  70. 응답
  71. 응답
  72. 응답
  73. 응답
  74. 응답
  75. 응답
  76. 응답
  77. 응답
  78. 응답
  79. 응답
  80. 응답
  81. 응답
  82. 응답
  83. 응답
  84. 응답
  85. 응답

Leave a comment

이메일 주소는 공개되지 않습니다.