473,395 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Need Query... Urgent Please help....

hi...

i have the table like this,

Table Name : sample
Total Records : 500000 (Consider like this)

Sample Records:
Expand|Select|Wrap|Line Numbers
  1. id ------------ name
  2. ======================
  3. 1 -------------- AAA
  4. 2 -------------- BBB
  5. 3 -------------- CCC
  6. 2 -------------- AAA
  7. 3 -------------- AAA
  8. 4 -------------- CCC
  9. 1 -------------- BBB
  10.  
i want to search based on the name, i need the id value which is must present
in the all the searching name.



i wrote the query like this... here i built the query dynamicaly.. if the search name is
increase...table self join is increase for each name... how to avoid this.. without
self join how to write the query.....

My query :

Query1:
Expand|Select|Wrap|Line Numbers
  1. select a.*
  2. from
  3.      sample a
  4.      inner join sample b on a.id=b.id
  5. where (a.name like 'AAA' and b.name ='BBB');
  6.  
Result:
Expand|Select|Wrap|Line Numbers
  1. 1 -------------- AAA
  2. 2 -------------- BBB
  3. 2 -------------- AAA
  4. 1 -------------- BBB
  5.  
This the result set for the above query.. but i need the unique id value.. if i
remove the duplicate.. the query will be slow...


Query2:
Expand|Select|Wrap|Line Numbers
  1. select a.*
  2. from
  3.      sample a
  4.      inner join sample b on a.id=b.id
  5. where (a.name like 'AA%' and b.name ='BB%');
  6.  
Result:
Expand|Select|Wrap|Line Numbers
  1. 1 -------------- AAA
  2. 2 -------------- BBB
  3. 2 -------------- AAA
  4. 1 -------------- BBB
  5.  
This the result set for the above query.. but i need the unique id value.. if i
remove the duplicate.. the query will be slow...


But need to fine tune these query...

Is there any other simple way to get the result...?

How to avoid the self join to get the result...

Can u any one help me...?


Thanks & Regards,
S.Ashokkumar.
Jul 3 '07 #1
1 1686
Atli
5,058 Expert 4TB
Thats weird. I ran you query on a table I created like this:
Expand|Select|Wrap|Line Numbers
  1. CREATE TABLE test
  2. (
  3.   ID INT NOT NULL,
  4.   Name VARCHAR(255) NOT NULL,
  5.   Primary Key (ID, Name)
  6. )
  7.  
And I get these results:
Expand|Select|Wrap|Line Numbers
  1. ID    Name
  2. --------
  3. 1    AAA
  4. 2    AAA
  5.  
How was your table created?
Jul 3 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: AVL | last post by:
Hi I'm working on indexing a website. I want to restict the search to only few file types like .doc,.txt and.ppt How to specify the file types in the 'ixsso.Query' object Presently i'n using...
0
by: Miguel Dias Moura | last post by:
Hello, I am working on an Asp.Net 2.0 / SQL 2005 web site. I am using profile to save the users info on the database. For example, I have the following structure: Public Structure Name...
15
by: Cheryl Langdon | last post by:
Hello everyone, This is my first attempt at getting help in this manner. Please forgive me if this is an inappropriate request. I suddenly find myself in urgent need of instruction on how to...
0
by: Balamurugan Ranganathan | last post by:
I want to calculate the execution time of a sql query through C#.net this is to analysis two queries to compare their execution time it is very Urgent Please help me Please help Me ...
3
by: Sandy911 | last post by:
I´ve never used charts in Access. Somehow I managed to format well shaped charts in Excel but I can´t find the way to understand how to create a report in Access that produces a bar or a pie chart...
2
by: mirzaali | last post by:
Hi All, I neeed to dispaly the data in html table tag Query :-select comp,total,funds from table1, WHICH WIL RETURN 3-RECORDSETS rs_query(0) rs_query(1) rs_query(2)
2
by: cj | last post by:
My code below gives me "SQL: Column 'BTN' is not found." It will work if I use an inner join or just join but those two joins don't return all the rows. BTN has 5 rows, but arcust01 has only has...
1
by: veerunrt | last post by:
Hi All, one column is having no of values separated by comma in the table that any one value should match with some other column of another table one value how to join in oracle I need result...
5
by: Justin | last post by:
Here's my XML: <?xml version="1.0" ?> <AppMode Type="Network"> <CurrentFolder Path="c:\tabs"> <Tabs> <FilePath>tabs\Justin.tab</FilePath> <FilePath>tabs\Julie.tab</FilePath> *****There could...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.