Simple example. Let’s select students with grades using left outer join:
SELECT DISTINCT s.id
FROM students s
LEFT JOIN grades g ON g.student_id = s.id
WHERE g.student_id IS NOT NULL
Now the same with left semi-join:
SELECT s.id
FROM students s
WHERE EXISTS (SELECT 1 FROM grades g
WHERE g.student_id = s.id)
The latter is much more efficient.
Related Posts:
- What is the difference between “INNER JOIN” and “OUTER JOIN”?
- What is the difference between “INNER JOIN” and “OUTER JOIN”?
- What is the difference between JOIN and UNION?
- MySQL Error: : ‘Access denied for user ‘root’@’localhost’
- What is an MDF file? [closed]
- ORA-00904: invalid identifier
- SQL Inner-join with 3 tables?
- Self Join to get employee manager name
- MySQL Error: : ‘Access denied for user ‘root’@’localhost’
- Why do we need “Relationships” between tables at all?
- How can I do a FULL OUTER JOIN in MySQL?
- Case statement in MySQL
- Difference between JOIN and INNER JOIN
- MySQL Multiple Joins in one query?
- Error Code: 2013. Lost connection to MySQL server during query
- SQL join on multiple columns in same tables
- how to drop partition without dropping data in MySQL?
- 1052: Column ‘id’ in field list is ambiguous
- 1052: Column ‘id’ in field list is ambiguous
- The ALTER TABLE statement conflicted with the FOREIGN KEY constraint
- What is it exactly a BLOB in a DBMS context
- What is difference between SQLite and SQL
- The backend version is not supported to design database diagrams or tables
- Create mysql table directly from CSV file using the CSV Storage engine?
- Simulate CREATE DATABASE IF NOT EXISTS for PostgreSQL?
- Postgres Error: More than one row returned by a subquery used as an expression
- How do I reset a sequence in Oracle?
- MySQL equivalent of DECODE function in Oracle
- what is the difference between triggers, assertions and checks (in database)
- Join vs. sub-query
- Conditional JOIN Statement SQL Server
- Solutions for INSERT OR UPDATE on SQL Server
- “select * into table” Will it work for inserting data into existing table
- Converting WordPress into Android or iPhone app
- What is an ORM, how does it work, and how should I use one? [closed]
- What is the difference between an ORM and an ODM?
- how to set the background color of the status bar during the launching phase [duplicate]
- How to show a loading gif while an APi is being called in xamarin android?
- 1000 * 60 * 60 * 24 * 30 results in a negative number [duplicate]
- LIKE vs CONTAINS on SQL Server
- Dial pad to get phone number (with Android button images)
- MySQL Error: : ‘Access denied for user ‘root’@’localhost’
- What’s the best way to search for a UPC code in a Database?
- Emulator: ERROR: x86 emulation currently requires hardware acceleration
- Emulator: ERROR: x86 emulation currently requires hardware acceleration
- ‘App not Installed’ Error on Android
- What is the difference between UNION and UNION ALL?
- Selecting COUNT(*) with DISTINCT
- ‘App not Installed’ Error on Android
- Draw a transparent circle onto a filled android canvas
- Case in Select Statement
- What is a stored procedure?
- How to use navigateUp to close the application
- What is the difference between varchar and nvarchar?
- SQL WITH clause example [duplicate]
- “unable to locate adb” using Android Studio [duplicate]
- “unable to locate adb” using Android Studio [duplicate]
- Can’t start Eclipse – Java was started but returned exit code=13
- Can’t start Eclipse – Java was started but returned exit code=13
- What exactly is “com.google.android.packageinstaller”
- Differences between arm64 and aarch64
- Unknown column in ‘field list’ error on MySQL Update query
- Unknown column in ‘field list’ error on MySQL Update query
- Converting double to string
- Android WebView err_unknown_url_scheme
- The wait operation timed out. ASP
- google console error `OR-IEH-01`
- What is SELF JOIN and when would you use it? [duplicate]
- The wait operation timed out. ASP
- Conversion failed when converting date and/or time from character string while inserting datetime
- How do I UPDATE from a SELECT in SQL Server?
- Install an apk file from command prompt?
- how to fix oracle ORA-01722 invalid number error
- How to decompile an APK or DEX file on Android platform? [closed]
- Install an apk file from command prompt?
- Android Studio Could not initialize class org.codehaus.groovy.runtime.InvokerHelper
- SQL query to select dates between two dates
- What’s the difference between INNER JOIN, LEFT JOIN, RIGHT JOIN and FULL JOIN? [duplicate]
- File extension .DB – What kind of database is it exactly?
- What is a database transaction?
- Error parsing data org.json.JSONException: Value
- MySQL – Operand should contain 1 column(s)
- SQL SELECT WHERE field contains words
- Conversion failed when converting date and/or time from character string while inserting datetime
- When should I use CROSS APPLY over INNER JOIN?
- MySQL “CREATE TABLE IF NOT EXISTS” -> Error 1050
- Insert Data Into Temp Table with Query
- What is this JavaScript “require”?
- MySQL create table if not exists and insert record only if table was created
- error, string or binary data would be truncated when trying to insert
- What does “|=” mean? (pipe equal operator)
- How to create Temp table with SELECT * INTO tempTable FROM CTE Query
- Rename a table in MySQL
- NOT IN vs NOT EXISTS
- SQL SELECT WHERE field contains words
- Online SQL Query Syntax Checker
- getting error HTTP Status 405 – HTTP method GET is not supported by this URL but not used `get` ever?
- How can I do an UPDATE statement with JOIN in SQL Server?
- My users get “net::err_name_not_resolved”
- How should I tackle –secure-file-priv in MySQL?