Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
Babli
Yak Posting Veteran
53 Posts |
Posted - 2007-01-19 : 03:56:59
|
| Hi,I have a child table which has all the file extensions that should be ignored.Usually when you have a single value that needs to be used with a like operaror we sayselect * from tbl where column not like '%.asp'But I want a result of a subqueryselect * from tbl where column not like (select * from childtable)How do i write in a query.Hope I am clear to you.Thanks in advanceBabli |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-01-19 : 04:04:48
|
How about this?Select *From tbl t1Where not exists(select * from childtable t2 where t2.column like '%' + t1.column ) Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
Babli
Yak Posting Veteran
53 Posts |
Posted - 2007-01-19 : 04:21:05
|
| No its not taking itThe above query's result is having the data that should ignored (when we say like "%') |
 |
|
|
Babli
Yak Posting Veteran
53 Posts |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-01-19 : 04:26:37
|
Harsh suggestion worked just fine, if you interchanged the comparison in the subquery.-- prepare sample datadeclare @tbl table (filename varchar(100))insert @tblselect 'peso.txt' union allselect 'peso.asp' union allselect 'harsh.asp'declare @childtable table (extension varchar(10))insert @childtableselect '.txt' union allselect '.mpg'select t.*from @tbl as twhere not exists (select null from @childtable as ct where t.filename like '%' + ct.extension) Peter LarssonHelsingborg, Sweden |
 |
|
|
Babli
Yak Posting Veteran
53 Posts |
Posted - 2007-01-19 : 04:31:17
|
| Yes its silly mistake.I should have interchanged the columns.Working very fineThank you so much |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-01-19 : 04:34:25
|
| Well. I hope you have learned something here.When given suggestions, try to understand them and figure out why they are working and how they are working.Not only will you improve your skills, but also train to see these small errors and correct them yourself.Good luck!Peter LarssonHelsingborg, Sweden |
 |
|
|
PrakashK
Starting Member
1 Post |
Posted - 2011-01-28 : 02:03:04
|
| Hi All,I want a similar query that you are discussing above. I have 2 tables namely 1. Location. 2. Contact.For each location_id in location table say 'asdf' one contact_id 'asdf' exists in contact table with same name as location_id.In addition to that there are some more cotacts where they will be appended '-001','-002'. so there are multiple contacts for same locationLOcation_id - asdf Contact -asdf asdf-001 asdf-002now I want all the contact_ids whic are like location_id.Prakash |
 |
|
|
|
|
|