In mysql I am using the following statement to find tables not like in a database.
show tables where `Tables_in_db` not like '%_table'
I am able to use the statement like below to find tables like in hive
show tables like '*table'
But unable to use the not like statement
show tables where `Tables_in_db` not like '*_table'
Is there an equivalent for this statement in Hive.
The below one can be used:
In SQL:
select * from tableName where columnName not like '%something%';
In Hive:
select * from tableName where not (columnName like '%something%');
Hope it helps.
Related
I would like to know how to write sql query to search string in all columns in a table.
i.e in single where condition
I have column1, column2,... column50 fields in a table
Right now am using query like
select * from tblist where column1 like '%searchstr%'OR column2 like '%searchstr%' OR ....it goes on
Is there anyway to write sql query to search string in all columns
In the case of your exact query as given, we can try using IN:
SELECT *
FROM tblist
WHERE 'searchstr' IN (column1, column2, ...);
If you really need to use LIKE here, then there is no real shortcut available.
you could save on the grunt work by using the metadata tables to generate your query and then run it. Eg:
select concat('%searchstr% like ',COLUMN_NAME,' OR ')
from information_schema.columns t
where table_name='t' /*change to the table name*/
Is it possible to write a query that applies to an entire database as opposed to one table.
So instead of usin:
select * from table_name where columnName = ?
Can I say select * db_tables from from db where the table contains the column A?
Is is possible?
thanks
You sure can!
SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME like '%A'
You cannot do SELECT * FROM all the tables, but you can run a query aganist multiple tables using other statements in SQL.
I have a tables in my database and would like to select specified tables by name:
abc_dshop_cats
abc_eshop_cats
abc_shop_cats
abc_shop_mods
abc_shopp_cats
How can I get these tables: abc_shop_cats and abc_shop_mods using the command below:
SHOW TABLES LIKE '%shop%'
And the command above is not working as return me all tables...
Thanks!
You could do like:
show tables like '%\_shop\_%'
This will get
abc_shop_cats
abc_shop_mods
but not
abc_dshop_cats
abc_eshop_cats
abc_shopp_cats
select table_name
from information_schema.tables
where table_name like '%shop%'
just use a normal SQL WHERE statement to do it.
SHOW TABLES WHERE Tables_in_mydbname LIKE '%_shop_%'
I'm trying to select the tables names in my database using this query
show tables LIKE 'table1%'
it's working fine but at the same table I have a version of the table with some columns empty called 'table1_blank'. When I use the above statement I get every table starting with table1 including the "blank", how do I exclude 'table1_blank' from the selection?
Thanks.
You can use multiple like clauses using the where condition for SHOW TABLES:
SHOW TABLES
FROM `dbname`
WHERE `Tables_In_dbname` LIKE 'table1%'
AND `Tables_In_dbname` NOT LIKE 'table1\_%';
'_' has special meaning. 'any one character', so you need to change like this..
EDITED
SELECT TABLE_NAME
FROM information_schema.TABLES
WHERE TABLE_SCHEMA = 'your database name'
AND TABLE_NAME LIKE 'table1%'
AND TABLE_NAME NOT LIKE 'table1\_%';
I am using mysql database ...
I have a table with col name food_type
in this field all the food types are in comma separated.
Now my problem is that i want to get the search result from them.
For Example:
Data in food_type col is like BBQ,Fast Food,Desi,Seafood,Vegetarian,
And I want to search BBQ,Seafood. But it can't give me the accurate result .
i try to use like in my sql query but same result :-(
How can I achieve this .
You could even use find_in_set() function
select * from table
where find_in_set('bbq',field_name) and find_in_set('Seafood',field_name)
but, as already written, your table needs to be normalized.
You can try 2 LIKE queries:
select * from table where field like "bbq" and field like "seafood"