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 all! We have been experiencing an issue on site where threads have been missing the latest postings. The platform host Vanilla are working on this issue. A workaround that has been used by some is to navigate back from 1 to 10+ pages to re-sync the thread and this will then show the latest posts. Thanks, Mike.
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 Select Problem

  • 28-08-2007 11:47am
    #1
    Registered Users, Registered Users 2 Posts: 10,148 ✭✭✭✭


    Hoping someone can help me out here . . .

    I have a table that contains a number of records. It has two fields, "Starter" and "Main Course". Typical data would look like this. . .

    Starter¦Main
    Soup, Beef
    Soup, Chicken
    Salad, Pork
    Soup, Beef
    Salad, Chicken
    Soup, Beef
    Salad, Pork
    etc . . .

    I need to try and select all similar pairs that occur in the table more than once. For example, in the above table, I would be looking to select Soup and Beef and Salad and Pork as they occur more than twice.

    Anyone help?


Comments

  • Registered Users Posts: 273 ✭✭stipey


    My first tip would be to search the web - because it certainly doesn't strike me as a query somebody would still need assistance with after a quick trawl through google.

    The answer is more likely to stick in your mind if you discover it yourself through google or MSDN.

    I'll point you in the direction however - the key words to search for are "count", "group by" and (if you want to find instances where a combination appears more than once "having". It would help if you were to add +sql to your search to ensure you only get hits relating to SQL.


  • Registered Users, Registered Users 2 Posts: 981 ✭✭✭fasty


    SELECT DISTINCT Starter, Main WHERE Count(Starter + Main) > 1


  • Registered Users, Registered Users 2 Posts: 5,102 ✭✭✭mathie


    SELECT starter, main, COUNT(*) AS Expr1
    FROM yourtable
    GROUP BY starter, main
    HAVING (COUNT(*) > 1)


  • Registered Users, Registered Users 2 Posts: 10,148 ✭✭✭✭Raskolnikov


    That works a peach Mathie, the problem I was having was that I was trying to put the (COUNT(*) > 1) into the WHERE part of my SQL query, that of course gave me an error.


Advertisement