473,396 Members | 1,827 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,396 software developers and data experts.

Search query between two tables

I'm working on search query for a troubleticket system.

There are two tables I want to search, the description in the tickets table
and the corresponding notes in the notes table. The problem is there is a
one to many relationship between the tickets (one) and the notes (many)
tables.

I only need the ticket number of any ticket that finds the search string in
the description or any of the corresponding notes.
Jul 23 '05 #1
2 3391
[posted and mailed, please reply in news]

Sorce (kp*****@ntihc.com) writes:
I'm working on search query for a troubleticket system.

There are two tables I want to search, the description in the tickets
table and the corresponding notes in the notes table. The problem is
there is a one to many relationship between the tickets (one) and the
notes (many) tables.

I only need the ticket number of any ticket that finds the search string
in the description or any of the corresponding notes.


SELECT ticketno, yadayada
FROM tickets t
WHERE t.description LIKE @searchstr
OR EXISTS (SELECT *
FROM notes n
WHERE n.ticketno = t.ticketno
AND n.comment LIKE @searchstr)

Note: if you in your posting include the following:

o CREATE TABLE statements for your tables.
o INSERT statments with sample data.
o The desired output given the sample.

You will get a tested answer. The above is just a guess on how your
tables may look like.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 23 '05 #2
Thanks, that is exactly what I needed.

"Erland Sommarskog" <es****@sommarskog.se> wrote in message
news:Xn*********************@127.0.0.1...
[posted and mailed, please reply in news]

Sorce (kp*****@ntihc.com) writes:
I'm working on search query for a troubleticket system.

There are two tables I want to search, the description in the tickets
table and the corresponding notes in the notes table. The problem is
there is a one to many relationship between the tickets (one) and the
notes (many) tables.

I only need the ticket number of any ticket that finds the search string
in the description or any of the corresponding notes.


SELECT ticketno, yadayada
FROM tickets t
WHERE t.description LIKE @searchstr
OR EXISTS (SELECT *
FROM notes n
WHERE n.ticketno = t.ticketno
AND n.comment LIKE @searchstr)

Note: if you in your posting include the following:

o CREATE TABLE statements for your tables.
o INSERT statments with sample data.
o The desired output given the sample.

You will get a tested answer. The above is just a guess on how your
tables may look like.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp

Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Zaphod Beeblebrox | last post by:
As much of this question relates to mysql, it may be OT? I'm trying to make a search engine for a reasonably complex database that was originally developed by someone else in Access. I've ported...
5
by: LRW | last post by:
Well, I have another question that's hard to ask, so I may end up over explaining the question. I have about 40 tables, all with a similar column structure. I want to be able to search through...
11
by: Adrian Parker | last post by:
I have a database of 200+ tables (two tables per school), each with 100 - 4000 records (one record per student). A contract I'm looking at wants to be able to do a search across all the tables,...
0
by: Robert Oschler | last post by:
I read a while back that MySQL will only use one index per query. (If this is not so, please tell me and point me to a doc that gives a good explanation of MySQL's current index usage policy). ...
2
by: TH | last post by:
I am (still :) working on a recipe database. Now I am trying to figure out how to set it up for an ingredient search. What I want it to be able to do is to search by one ingredient, sometimes by...
3
by: Jan Szymczuk | last post by:
I am trying to create a query that will show me who is phoning who in an organisation from available Telephone Billing information. I am creating a MSAccess 2000 database with a few few tables, two...
0
by: | last post by:
I have a question about spawning and displaying subordinate list controls within a list control. I'm also interested in feedback about the design of my search application. Lots of code is at the...
5
by: kanley | last post by:
I have a main table with a text description field. In this field, its populated with a string of data. I need to identify from this string of data the name of the vendor using some keywords. I...
0
by: JamesOo | last post by:
I have the code below, but I need to make it searchable in query table, below code only allowed seach the table which in show mdb only. (i.e. have 3 table, but only can search either one only,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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...
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.