Subject: Breaking-News: remedy prevents strokes

From: Breaking News: Reverse-Diabetes <[email-masked]>
Date: Wed, 26 Nov 2014 13:11:06 -0800

WebMD...

Diabetes Guide

Cure Details Released November 26, 2014

You will now be able to control your Blood Glucose and stop suffering from erratic blood levels.

View Cure Details

This can Bring your health back from the Brink in Days. Big Pharmaceutical Companies are working to prevent this info from becoming Mainstream -

View Exposed Remedy for Epidemic

Type 1 | Type 2 | Gestational | Pre-Diagnosis

Support - Resources

vcv-communications group

Two Pineway Drive Daleville, AL 36322 Unsubscribe Here

SELECT EXISTS(SELECT * FROM table1 WHERE ...)
per the documentationPer a comment below:
SELECT EXISTS(SELECT 1 FROM table1 WHERE ...)

share|improve this answer

edited Sep 4 '13 at 22:59
Simon Arnold

6,14722341

answered Nov 4 '09 at 20:59
Chris Thompson

18.9k54575

1

+1 - I never used "Exists" for this operation in MySQL. James Black Nov 4 '09 at 21:02

64

Avoid using SELECT * wherever possible, as the * character will cause an extra lookup; remember, SELECT 1 FROM table1 WHERE ... will have the same net effect sans the overhead in this case. Dereleased Nov 4 '09 at 21:28

@Dereleased very good point. Modified my post. Thanks Chris Thompson Nov 4 '09 at 22:48

14

Test with ...EXISTS( SELECT 1/0 FROM someothertable). For SQL Server & Oracle - it makes no difference to use *, 1 or NULL because EXISTS only tests for a boolean based on 1+ of the WHERE criteria matching. OMG Ponies Nov 4 '09 at 23:28

@OMG, just tried on MySQL 5.0.77 and your query does work, suggesting that the * may not matter. Matthew Flaschen Apr 13 '11 at 18:20

27

Guys, it says right in the documentation linked to in this answer, 2nd paragraph, "Traditionally, an EXISTS subquery starts with SELECT *, but it could begin with SELECT 5 or SELECT column1 or anything at all. MySQL ignores the SELECT list in such a subquery, so it makes no difference." Mark Feb 11 '12 at 0:39

4

@ChrisThompson : what happens when the statement is executed? I mean what does the result set contain? Ashwin Nov 4 '12 at 11:37

4

@Ashwin, it contains whether a 0 (not exists) or 1 (exists). fedorqui Feb 7 '13 at 9:09

Does the statement return bool type or unsigned char type? I am developing using the C API and I need to know this. Thanks. Luka Feb 25 at 6:43

1

@Luka according to the docs, it returns a bool type. Chris Thompson Feb 25 at 13:51