473,782 Members | 2,525 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

39 New Member
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...tabl e 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 1706
Atli
5,058 Recognized Expert Expert
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
1456
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 the following syntax: dim ixQuery ' Index Server query object. set ixQuery = Server.CreateObject("ixsso.Query")
0
1351
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 Public First As String Public Last As String End Structure
15
4644
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 communicate with a MySQL database table on a web server, from inside of my company's Access-VBA application. I know VBA pretty well but have never before needed to do this HTTP/XML/MySQL type functions.
0
7426
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 Thanks in Advance Balamurugan Ranganathan
3
2319
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 based on a one record (summarized) query. For example: I have a table with statistics. I run a query that sums and gets the total for each category and calculates the percentages over the totals. I need a report that shows those results in a well...
2
1267
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
1175
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 matching records for 2 of them. I need the other 3 returned with nulls in the fields from arcust01. How can I do this?
1
4390
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 for this query: SELECT DISTINCT oeh.ORDER_NUMBER AS sales_order_number, oeh.REQUEST_DATE AS CUST_REQ_DATE,
5
2163
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 be 1 of these or 100....quantity can change***** </Tabs>
0
9641
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10313
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10080
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9944
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7494
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6735
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4044
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3643
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2875
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.