Win a copy of Spark in Action this week in the Open Source Projects forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Finding a Disjoint set between two tables

 
Ranch Hand
Posts: 175
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

 Please find the SQLfiddle link  http://sqlfiddle.com/#!9/89c76/2


How can I do this in a single query for all the games, there can be many types of games. I cant specify the games explicitly, instead, I want to write the query to fetch all the playerids who are not playing a game for each of the game some thing like this



the above query is giving only one record. I need like this

Result:
------------------------
game1 | 4,5,6  
------------------------
game2 | 4,6
------------------------
game3 | 1,2,3,5,6
------------------------
....
 
Chandra shekar M
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need something like a forloop, which can loop over the games and find the players not playing that game. Can I do this in SQL or should I write a procedure
 
author & internet detective
Posts: 40035
809
Eclipse IDE VI Editor Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, this can be done in raw SQL. It's not particular efficient; doing a loop behind the scenes. But for small datasets, that is fine.



The nested query gets the games a player played. If there aren't any for that player/match combo, the outer query includes the data. The distinct is because the cartesian product of the outer query creates duplicate rows.
 
Chandra shekar M
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jeanne Boyarsky, it helped
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This may prove to be a bit cheaper than Jeanne's solution:

 
Today's lesson is that you can't wear a jetpack AND a cape. I should have read this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic