Selecting a table and filtering by several values from one column as well as a value from another

jgozal

I'm trying to query a table so that if

table1:

x   y   z
gg  1   E
ll  1   E
ff  2   NA
ee  2   E  
rr  3   E
ww  3   NA

The query returns only those rows with 1 and 2 in column y that do not have an "NA" string in column z like this:

x   y   z
gg  1   E
ll  1   E
ee  2   E  

I tried doing something like:

SELECT * FROM table1 WHERE (((y = 1) OR (y = 2)) AND (z <> "NA"));

I also tried:

SELECT * FROM table1 WHERE y IN (1,2) AND (z <> "NA");

None of these worked.

fabulaspb

Try this SQL query. I think your z column may contain extra spaces.

SELECT * FROM Table1 AS T
WHERE T.y IN(1,2)
          AND T.z NOT LIKE '%NA%'

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

SQL - Selecting unique values from one column then filtering based on another

From Dev

SQL - Selecting unique values from one column then filtering based on another

From Dev

MySQL Count values from one column with selecting a value from another column

From Dev

Selecting data from table where sum of values in a column equal to the value in another column

From Dev

SQL - Selecting a column from another table twice with different values

From Dev

Selecting data from one table based on the value of another

From Dev

Join multiple values from one column, selected from another table

From Dev

mysql insert unique values from one column to a column of another table

From Dev

Inputing column values in one table from another related table

From Dev

Inputing column values in one table from another related table

From Dev

Selecting values from a table where values from one column is divided into multiple columns

From Dev

Getting id values from a column and then get value from another table

From Dev

Select values from one table depending on referenced value in another table

From Dev

selecting average value from group of same with max on another for several columns

From Dev

Fetching several values from the same column in a table

From Dev

Fetching several values from the same column in a table

From Dev

insert statement one column from another table rest of the columns is values

From Dev

Using values from a field in one table as column name for field in another

From Dev

Insert INTO from one table to another and change column values

From Dev

Selecting rows from one table where value and order from another in MYSQL

From Dev

Selecting from table into a column

From Dev

Aggregating values in one column by their corresponding value in another from two files

From Dev

Copy Column Value from One table into Another Matching IDs

From Dev

update column values by looking up value from another table

From Dev

MYSQL query - simple way to return all values from one column based on a DISTINCT value in another column in the same table?

From Dev

selecting a specific number from a column in a table into another table

From Dev

selecting unique rows from one table according to another table and then sorting it

From Dev

Jquery selecting values from on table while in another table

From Dev

inserting table values from one table to another

Related Related

  1. 1

    SQL - Selecting unique values from one column then filtering based on another

  2. 2

    SQL - Selecting unique values from one column then filtering based on another

  3. 3

    MySQL Count values from one column with selecting a value from another column

  4. 4

    Selecting data from table where sum of values in a column equal to the value in another column

  5. 5

    SQL - Selecting a column from another table twice with different values

  6. 6

    Selecting data from one table based on the value of another

  7. 7

    Join multiple values from one column, selected from another table

  8. 8

    mysql insert unique values from one column to a column of another table

  9. 9

    Inputing column values in one table from another related table

  10. 10

    Inputing column values in one table from another related table

  11. 11

    Selecting values from a table where values from one column is divided into multiple columns

  12. 12

    Getting id values from a column and then get value from another table

  13. 13

    Select values from one table depending on referenced value in another table

  14. 14

    selecting average value from group of same with max on another for several columns

  15. 15

    Fetching several values from the same column in a table

  16. 16

    Fetching several values from the same column in a table

  17. 17

    insert statement one column from another table rest of the columns is values

  18. 18

    Using values from a field in one table as column name for field in another

  19. 19

    Insert INTO from one table to another and change column values

  20. 20

    Selecting rows from one table where value and order from another in MYSQL

  21. 21

    Selecting from table into a column

  22. 22

    Aggregating values in one column by their corresponding value in another from two files

  23. 23

    Copy Column Value from One table into Another Matching IDs

  24. 24

    update column values by looking up value from another table

  25. 25

    MYSQL query - simple way to return all values from one column based on a DISTINCT value in another column in the same table?

  26. 26

    selecting a specific number from a column in a table into another table

  27. 27

    selecting unique rows from one table according to another table and then sorting it

  28. 28

    Jquery selecting values from on table while in another table

  29. 29

    inserting table values from one table to another

HotTag

Archive