Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

SQL query not working help needed

  • 18-08-2007 6: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,584 ✭✭✭✭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: 35,731 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