Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.
Hi all, please see this major site announcement: https://www.boards.ie/discussion/2058427594/boards-ie-2026

SQL query not working help needed

  • 18-08-2007 06:16PM
    #1
    Registered Users, Registered Users 2 Posts: 1,488 ✭✭✭


    i need to compare the two fields from a database

    ie if prediction = 1 and result = 1 then it will display the row in which this occurance happens

    i tried the foolowing

    "SELECT actual, predicted FROM Results WHERE actual=predicted;"


    but get the following error ms - illegal mix of collations for operation '='

    thanks for all the help guys


Comments

  • Registered Users, Registered Users 2 Posts: 26,449 ✭✭✭✭Creamy Goodness


    you can't do WHERE actual = precdicted i don't think

    you'd need to check that actual is equal to 1 and predicted is equal to 1.

    because you more than likely have the actual column set to be an int of somesort but you're using a string in the statement.


  • Registered Users, Registered Users 2 Posts: 1,488 ✭✭✭AdrianII


    sorry,
    both colums are set to be strings, the results of the two columns can either be Home, draw or away, so i need it to display the results where

    predicted = Home and result = Home

    or

    predicted = away and result = away


    can this be done or is it way too hard


  • Moderators, Arts Moderators Posts: 36,261 Mod ✭✭✭✭pickarooney


    I would recommend storing these kind of values as integers for comparison purposes, e.g. home is 0 and away is 1. Whatever you're interpreting the SQL request with should output the string equivalent.

    I don't really know why you get the error when comparing strings, but aht happens when you use:

    SELECT actual, predicted FROM Results WHERE actual LIKE predicted

    ?

    Also, your first post is a little confusing - all this command will return is a series of

    Home, Home
    Home, Home
    Away, Away
    Home, Home

    etc.

    I imagine you'd also want to return some other info from the rows where matches occur, no,


  • Registered Users, Registered Users 2 Posts: 545 ✭✭✭ravydavygravy


    you nearly wrote it yourself... :-)
    SELECT * FROM results 
     where 
       (actual = 'Home' AND predicted = 'Home') 
     OR 
       (actual ='Away' AND predicted = 'Away');
    

    This should do the trick (MySQL anyway - not sure about T-SQL, but I suspect it'll be the same)


  • Registered Users, Registered Users 2 Posts: 1,488 ✭✭✭AdrianII


    thanks for the posts, yep got the code turns out one column was a varchar and the other a string column

    thanks for the replies


  • Advertisement
Advertisement