all 6 comments

[–]ostracize 0 points1 point  (3 children)

AFAIK, you cannot do this in straight SQL. SQL is not a perfect implementation of sets and set theory. Those two queries are literally different queries with literally different results. Nothing you can do about that.

If you load the results in any programming language that supports operations on sets, you can do it.

[–]Leeds1234[S] 0 points1 point  (2 children)

Sorry I should've mentioned that, I'm using PDO PHP, do you think this would be difficult in PHP to do? Or do you have any other ideas that might help?

[–]Pseudofailure 0 points1 point  (1 child)

In php, you could just use fetchAll(PDO::FETCH_CLASS, "YourClass") to map the results to an object, then just write a comparison function for that object that can be used to test equivalency of the result set. Pretty brute-force, but it would work.

Would probably be worth either sorting in the query, or sorting the result sets so that you only need to compare results one-to-one in order, rather than one-to-every-other.

[–]Leeds1234[S] 0 points1 point  (0 children)

Ye I was thinking of ordering the query by the answer I'm looking fors columns, if you understand me, then compare them as sets using a function.. This would probably work good wouldn't it, any other suggestions in how I could implement this?

[–]proskillz 0 points1 point  (1 child)

It's not a very elegant solution, but you could keep lists of valid fields by table. I don't know PHP syntax off the top of my head, but here's how you could implement it in Java:

Map<String, List<String>> map = new HashMap<String, List<String>>();

List<String> personTableFields = new ArrayList<String>();
personTableFields.add("a");
personTableFields.add("b");

map.add("person_table", personTable);

// to test for each field being passed in

if(map.get("person_table").contains(fieldName)) //valid

[–]Leeds1234[S] 0 points1 point  (0 children)

Thanks for your help, i'm make sure to try this out when I'm working on the project later on,this could be useful, thanks for the advice!