Home  Fees/Services  Microsoft Access Templates  Tutorials  Access Download  Articles  Search  Contact  Privacy  Links

Access Query Examples
Query Tutorials in SQL
Self Join Query Examples
Joining Table onto Itself

Self Join: Joining Tables onto Itself Microsoft Access 2007 Query Help
Access SQL Tutorials




MS SQL Tutorials:
Query Too Complex
Aggregate Functions
Choose Function
SQL Not Operator
More Choose Functions
Crosstab Query Tutorial
Crosstab Query Advanced
DateTime Query
Delete Query Tutorial
External Link Query
Access Report Filter Query
Group By Clause
Access Having Clause
Histogram Query Tutorial
Insert Into SQL Query
Master/Detail Updates
Order By Dynamic
Access Parameter Query
Predicate Query Example
Self Join Query Tutorial
Scalar Query Example
Child/Parent Table Query
Select Statement Tutorial
Select Top 1 Query
Union Query Example
Update Query

Multi-Select Parameter Forms Query Tutorial


Self Join

SQL Self Join Example

Access self join:  In this update query example we use the self join query technique to update each Emp's salary by 10%.  There are at least two ways to do this update.

Example c) (below) is supposed to work but I get errors in Access.  It is called a correlated subquery - if you can tell me what is wrong with it I'd really appreciate it.

Self Join Query Code:

a)  Update M_Emp as A INNER JOIN M_Emp as B ON A.Emp_ID = B.Emp_ID SET A.Salary = B.Salary*1.1

b)  Update M_Emp as A, M_Emp as B Set A.Salary=B.Salary * 1.1
Where A.Emp_ID=B.Emp_ID

c)  Update M_Emp as A set A.Salary = (Select Salary * 1.1 from M_Emp Where M_Emp.Emp_ID = A.Emp_ID)

Note:  I have added a another feature to this self join query example - Aliases.  Aliases are where you use 'as' to establish a short nickname for a table or a field.  This alias feature helps when you have long table names or are trying to do a correlated subquery.

Additional Self Join Examples:

Self Join in Visual Basic Detail Master Update

RunSql ("Update Tasks set Task_Complete=False " & _ " where Task_ID=" & Me.Task_ID). End If. End Sub. Ok... this is more of an SQL example than a visual ...

Self Join Update Table Data in Access

Update M_Emp as A set A.Salary = (Select Salary * 1.1 from M_Emp Where M_Emp.Emp_ID = A.Emp_ID) ...

 

Access Self Join Query for Inventory Calculations Example

RunSQL "Update M_Inventory set inv_qty=inv_qty+" & Nz(hold_qty, 0) & " where barcode=" & Me.BarCode DoCmd.RunSQL "Update M_Inventory set inv_qty=inv_qty-"







Have errors?  No doubt we can answer your question quickly and easily.  Simple SQL questions get simple answers at no charge via email.





Popular Database Templates:

Reservations Tracking Access Template Database

Asbestos Survey Project Access Templates


Document Revision Control Database Templates


Contact Information

Microsoft Access Help

Microsoft Access 2007 Query Tutorial

Free SQL Tutorial & Query Solutions Workaround Runtime Examples Samples