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

SQL select statement

Options
  • 05-07-2019 10:25pm
    #1
    Registered Users Posts: 915 ✭✭✭


    Trying to figure out an SQL select statement that takes in a number and queries 2 fields for a match and provides all information if the match is correct.

    I can query 1 field which works like so
    select * from Table where CurrentPin = ?

    How can i query 2 fields. Thought this would work but doesnt
    select * from Table where CurrentPin = ? or PreviousPin = ?

    Any ideas?


Comments

  • Registered Users Posts: 1,198 ✭✭✭bren2002


    Look up sql joins


  • Closed Accounts Posts: 4,007 ✭✭✭s7ryf3925pivug


    union two selects one for each criterion


  • Registered Users Posts: 1,454 ✭✭✭FastFullBack


    logistic wrote: »
    Trying to figure out an SQL select statement that takes in a number and queries 2 fields for a match and provides all information if the match is correct.

    I can query 1 field which works like so
    select * from Table where CurrentPin = ?

    How can i query 2 fields. Thought this would work but doesnt
    select * from Table where CurrentPin = ? or PreviousPin = ?

    Any ideas?
    What exactly is not working with the OR statement? Based on the details you provided it should work fine.

    Can you post the exact SQL?


  • Closed Accounts Posts: 22,651 ✭✭✭✭beauf


    logistic wrote: »
    Trying to figure out an SQL select statement that takes in a number and queries 2 fields for a match and provides all information if the match is correct.

    I can query 1 field which works like so
    select * from Table where CurrentPin = ?

    How can i query 2 fields. Thought this would work but doesnt
    select * from Table where CurrentPin = ? or PreviousPin = ?

    Any ideas?

    Not sure what you are asking....

    ...to find where both fields are identical is an AND not an OR..
    ...you could just have CurrentPin = PreviousPin

    if thats what you meant. hard to know.


Advertisement