Comments on: MINUS query in MySQL http://www.terminally-incoherent.com/blog/2005/08/19/minus-query-in-mysql/ I will not fix your computer. Tue, 04 Aug 2020 22:34:33 +0000 hourly 1 https://wordpress.org/?v=4.7.26 By: Szabolcs Hodosi http://www.terminally-incoherent.com/blog/2005/08/19/minus-query-in-mysql/#comment-22633 Sat, 14 Jul 2012 21:36:00 +0000 http://www.terminally-incoherent.com/blog/?p=192#comment-22633

Didn’t it easier to use outer joins instead of left/right inner join with allowing NULL values explicitly? In Database theory the outer join is for this purpose, otherwise the article is good.

Reply  |  Quote
]]>
By: JAMES YEATRAKAS http://www.terminally-incoherent.com/blog/2005/08/19/minus-query-in-mysql/#comment-16458 Sat, 10 Jul 2010 16:31:01 +0000 http://www.terminally-incoherent.com/blog/?p=192#comment-16458

Table 1 is a roster of Bowlers who can belong to one or many bowling centers. Table 2 is a roster of bowlers signed up for an event today. I list my bowling center roster with all names for that bowling center who are elegible to signup for the event roster (table 2) It is possible to signup bowlers at different times. After I signup a bowler and close the signup page, when I go back to the signup page I do not want to see the bowlers who have already signed up.

I have tried many sql select statements, none of which produce the desired result:

1) SELECT DISTINCT BH.BID
FROM BOWLERS_HOUSE BH
LEFT JOIN EVENT_ROSTER ER
ON ER.BID = BH.BID
WHERE ER.HOUSE_ID = 40
AND ER.EVENT_ID = 201007073010100101010300
AND ER.BID IS NULL; Note: returns empty result

2) SELECT DISTINCT BH.BID
FROM BOWLERS_HOUSE BH
WHERE BH.HOUSE_ID = 40
AND (BH.BID) NOT IN
(“SELECT ER.BID FROM EVENT_ROSTER ER WHERE EVENT_ID = 201007073010100101010300 AND ER.HOUSE_ID = 40”);Note returns all BID’s in Table 1

3) SELECT BOWLERS_HOUSE.BID
FROM BOWLERS_HOUSE LEFT JOIN EVENT_ROSTER ON BOWLERS_HOUSE.BID=EVENT_ROSTER.BID
WHERE EVENT_ROSTER.BID IS NULL;
Note: returns the bowlers who have aready signed up and are on Table 2, I want only the bowlers who have not ALREADY signed up that are NOT ON table 2

I can run the program the way it is or I can build a very convoluted compare routine to eliminate the Table2 records from my display of the House roster, but need something that works. Oh, I tried SQL MINUS, but of course mysql disregards this very useful tool.

Any ideas?
Thanks in advance!

Reply  |  Quote
]]>
By: NdR http://www.terminally-incoherent.com/blog/2005/08/19/minus-query-in-mysql/#comment-13902 Fri, 01 Jan 2010 23:03:33 +0000 http://www.terminally-incoherent.com/blog/?p=192#comment-13902

Good solve! but I have problem, how to select that with a criteria e.g where id=something?

Reply  |  Quote
]]>
By: Vardhan http://www.terminally-incoherent.com/blog/2005/08/19/minus-query-in-mysql/#comment-13673 Mon, 30 Nov 2009 05:14:46 +0000 http://www.terminally-incoherent.com/blog/?p=192#comment-13673

Hey What is the need of ‘WHERE computers.username IS NULL’ here

Reply  |  Quote
]]>
By: Jamison Dance http://www.terminally-incoherent.com/blog/2005/08/19/minus-query-in-mysql/#comment-12954 Mon, 10 Aug 2009 18:45:20 +0000 http://www.terminally-incoherent.com/blog/?p=192#comment-12954

Thank you google, for taking me here, and thank you sir for answering my question. You just saved me bunches of time.

Reply  |  Quote
]]>
By: Diesel Station http://www.terminally-incoherent.com/blog/2005/08/19/minus-query-in-mysql/#comment-11366 Mon, 26 Jan 2009 03:03:18 +0000 http://www.terminally-incoherent.com/blog/?p=192#comment-11366

Very nice, exact solution that I was looking for. It is a simple solution yet difficult unless you look at the problem in different way. Good job.

Reply  |  Quote
]]>
By: Touseef Zafar http://www.terminally-incoherent.com/blog/2005/08/19/minus-query-in-mysql/#comment-11312 Wed, 21 Jan 2009 05:18:44 +0000 http://www.terminally-incoherent.com/blog/?p=192#comment-11312

yeah…thats a very nice solution to this problem…
very good
:)

Reply  |  Quote
]]>
By: Michael Whittaker http://www.terminally-incoherent.com/blog/2005/08/19/minus-query-in-mysql/#comment-4846 Tue, 19 Jun 2007 12:46:16 +0000 http://www.terminally-incoherent.com/blog/?p=192#comment-4846

Thanks, I had the same problem and also just stared at the screen ;)

Reply  |  Quote
]]>