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 select statement

  • 05-07-2019 9:25pm
    #1
    Registered Users, Registered Users 2 Posts: 922 ✭✭✭


    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 Posts: 1,208 ✭✭✭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,466 ✭✭✭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.


Advertisement