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

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


    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?


Welcome!

It looks like you're new here. Sign in or register to get started.

Comments

  • Registered Users, Registered Users 2 Posts: 1,212 bren2002
    ✭✭✭


    Look up sql joins


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


    union two selects one for each criterion


  • Registered Users, Registered Users 2 Posts: 1,478 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,648 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.


Welcome!

It looks like you're new here. Sign in or register to get started.
Advertisement