ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

SQL query

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • SQL query

    Hi,

    To select multiple values with in a field for file we use IN.

    The IN operator is a shorthand for multiple OR conditions but what about if we want to select multiple values with 'AND' condition not with 'OR' condition from a column with in a table or from a field name from a file.



    Thanks....

  • #2
    There is no shorthand for an AND condition and it doesn't make logical sense anyway. If you were to code the statement IF FIELDA = 'ABC' AND FIELDA = 'DEF'; no records would ever be selected because the contents of FIELDA cannot be two different things at the same time.

    Comment


    • #3
      it can be for example we have two fields A & B and we have multiple Values of A and same for B so if I want to select all the records for field B for Field A thn how can we select such records for example:-


      File1 has two fields A & B

      A B
      abc x1
      abc x1
      abc y1
      xyz xy1
      xyz xy2


      so if i want to select all the records from above file1 for uniquely identifying all the corresponding values for A fields i mean i want to select all the associated values of 'abc' whether it is x1,y1 etc.

      then how can i get it in a generic way because here values 'abc' is just an example there might be thousands of such entries in a file in which i want to select all the associated values of Field A to B then here comes the scenario of ' AND' condition like here i know in above table since limited values so i can do select * from file1 where field A = 'abc' and Field B in ('x1', 'y1' )
      but what about the case where there are thousands of such pairs for which how can we write SQL query to select such matching pair records?


      Thanks...

      Comment


      • #4
        I'm sorry, but I don't know exactly what you are asking. To select records from a file, you have to know what combination of values in what fields make the record eligible for selection. You can either hard code that logic in the WHERE clause or another way would be to create a table with the selection values in it and use that to join to the original table.

        Comment

        Working...
        X