0

I need to find 240 unique values in my table which contains 300.000 rows.

my unique values are like:
elephant,turtle,bird,turkey,snake
(I have list all of them)

I have tried:

Where column_name like 'snake'
    or column_name like 'bird'
    or column name like 'snake' etc...

but I'm not sure it is a good way to find my values.

Arulkumar
  • 12,966
  • 14
  • 47
  • 68
Hw3zs
  • 7
  • 6
  • 2
    Select DISTINCT ColumnName From YourTableName – Brad Sep 29 '21 at 13:38
  • Make it easy, and possible, to assist you - show us some sample table data _and the expected result_ - all as formatted text (not images.) [mcve] – jarlh Sep 29 '21 at 13:41
  • Your question is still not clear; you want to find all the distinct values, and there are 240 of them, or you want to find only a specific list of those 240 values? – Stu Sep 29 '21 at 13:42
  • i want to find specific 240 values from 300.000 in my table – Hw3zs Sep 29 '21 at 13:45
  • Where is your list, in a table, the result of another query, or a hard coded list? – Stu Sep 29 '21 at 13:50
  • I have list in excel file – Hw3zs Sep 29 '21 at 14:01

2 Answers2

1

Try this:

> select distinct animal_name from your_300000_table;

So, suppose your table is this:

> create table animals (
    animal_id numeric(10) primary key,
    animal_type varchar(32) not null, -- here you have snake, bird, you name it
    added_date datetime2,
    location_lat numeric(11,8),
    location_lon numeric(11,8)
  );
> select distinct animal_type from animals;
> -- this will yield the expected result.

    
Pablo Santa Cruz
  • 176,835
  • 32
  • 241
  • 292
1

If you want to find the row with the values from a list you can do

SELECT * FROM animals WHERE name IN ('elephant','cat');
Maxime C.
  • 37
  • 11
  • so if i want find all 240 rows with values i have to make IN ('elephant', 'cat', ... another 240 values) ? – Hw3zs Sep 29 '21 at 13:48
  • If you wanne find all the rows who have value elephant,cat, ... you will need to do that. If you wanne find all unique animals use @Pablo Santa Cruz awnser. – Maxime C. Sep 29 '21 at 13:51
  • is any huge difference if I use for example Where column_name LIKE 'snake' or column_name like 'bird' or column name like 'snake' ... ? – Hw3zs Sep 29 '21 at 13:58
  • 1
    https://stackoverflow.com/questions/3074713/in-vs-or-in-the-sql-where-clause should awnser your question. Using WHERE IN would also be a lot cleaner – Maxime C. Sep 29 '21 at 14:02