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.

SQL select statement

  • 05-07-2019 10:25PM
    #1
    Registered Users, Registered Users 2 Posts: 929 ✭✭✭


    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, Registered Users 2, Paid Member Posts: 1,223 ✭✭✭bren2002


    Look up sql joins


  • Closed Accounts Posts: 3,999 ✭✭✭s7ryf3925pivug


    union two selects one for each criterion


  • Registered Users, Registered Users 2 Posts: 1,495 ✭✭✭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,461 ✭✭✭✭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