473,402 Members | 2,055 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,402 software developers and data experts.

1 query on 3 tables?

Hi all,

I have been reading my books about this, but can't seem to find the
solution.

Example:

Picture 3 tables:

TABLE_1
-------------
item_id INT
subject VARCHAR
body TEXT
------------

TABLE_2
-------------
item_id INT
subject VARCHAR
body TEXT
------------

TABLE_1
-------------
item_id INT
subject VARCHAR
body TEXT
------------

All 3 tables have a FULLTEXT index on SUBJECT.

I want to create 1 query that searches ALL 3 tables with a MATCH (subject)
AGAINST ('$keywords' IN BOOLEAN MODE) and have the results neatly underneath
eachother as if I only searched 1 table.

Is this even possible? If not, what would be the workaround?

Thanks.
Jul 20 '05 #1
3 1507
oops, last table_1 in the example should read : TABLE_3
Jul 20 '05 #2

"Ondernemer" <no**@email.com> wrote in message
news:10*************@corp.supernews.com...
Hi all,

I have been reading my books about this, but can't seem to find the
solution.

Example:

Picture 3 tables:

TABLE_1
-------------
item_id INT
subject VARCHAR
body TEXT
------------

TABLE_2
-------------
item_id INT
subject VARCHAR
body TEXT
------------

TABLE_1
-------------
item_id INT
subject VARCHAR
body TEXT
------------

All 3 tables have a FULLTEXT index on SUBJECT.

I want to create 1 query that searches ALL 3 tables with a MATCH (subject)
AGAINST ('$keywords' IN BOOLEAN MODE) and have the results neatly underneath eachother as if I only searched 1 table.

Is this even possible? If not, what would be the workaround?

Thanks.

How about this?

CREATE TABLE Table1(
item_id INT,
subject VARCHAR(35),
body TEXT,
FULLTEXT(subject));

CREATE TABLE Table2(
item_id INT,
subject VARCHAR(35),
body TEXT,
FULLTEXT(subject));

CREATE TABLE Table3(
item_id INT,
subject VARCHAR(35),
body TEXT,
FULLTEXT(subject));

insert into table1 values(1,'Subject1','Some text'),(2,'Subject2','Some more
text');
insert into table2 values(15,'Subject1','Some
text'),(2,'Subject4','ABABABA');
insert into table3 values(11,'Subject1','Some text');

SELECT item_id,subject,body FROM Table1 WHERE MATCH(Subject)
AGAINST('Subject1' IN BOOLEAN MODE)
UNION SELECT item_id,subject,body FROM Table2 WHERE MATCH(Subject)
AGAINST('Subject1' IN BOOLEAN MODE)
UNION SELECT item_id,subject,body FROM Table3 WHERE MATCH(Subject)
AGAINST('Subject1' IN BOOLEAN MODE);

You can probably accomplish the same thing using MERGED tables though I
haven't worked with merged tables.

Regards,
Rich
Jul 20 '05 #3
On 23 Dec 2004 "Ondernemer" <no**@email.com> wrote in
news:10*************@corp.supernews.com:

<snip>
All 3 tables have a FULLTEXT index on SUBJECT.

I want to create 1 query that searches ALL 3 tables with a MATCH
(subject) AGAINST ('$keywords' IN BOOLEAN MODE) and have the
results neatly underneath eachother as if I only searched 1 table.

Is this even possible? If not, what would be the workaround?


Look up UNION queries. Basically they let you run multiple queries
and then merge the output.

The syntax is

SELECT ...
UNION [ALL | DISTINCT]
SELECT ...
[UNION [ALL | DISTINCT]
[...]

So you would just need to write your 3 SELECT queries and then join
them by UNION ALL.

--
Graham Drabble
If you're interested in what goes on in other groups or want to find
an interesting group to read then check news.groups.reviews for what
others have to say or contribute a review for others to read.
Jul 20 '05 #4

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

Similar topics

7
by: Phin | last post by:
I need your HELP! I've seen all the posts on using Crystal Reports within vs.net (vb.net) and changing a SQL query at runtime. When I tried to pass in a dataset into the crystal report at...
3
by: Paradigm | last post by:
I am using Access 2K as a front end to a MYSQL database. I am trying to run a Union query on the MYSQL database. The query is (much simplified) SELECT as ID from faxdata UNION SELECT as ID ...
3
by: dk | last post by:
Hi all, Would appreciate some advice on the following: I am trying to speed up an Access database connected to a SQL Server back-end. I know I can use a pass-through query to pass the sql...
3
by: Hyphessobricon | last post by:
Hallo, Indeed, a count of a query with a group by function gives more records than there are and so for-next structures don't function. How is this to be mended. Anyone? Everyone in fact....
2
by: =?Utf-8?B?Q2hyaXM=?= | last post by:
How can I run this query against a table in my Access database? I don't know hwo to use it in C#. In VB I would use .Recordset = "some sql statement". How do I do this in C#? //I get a vlaue...
3
by: KNN | last post by:
Hi I have some tables with hidden attribute set to 1. In the query desgn view , I do not see these tables as expected. But, If I choose the query wizard to create a new query, then i do see...
16
by: ARC | last post by:
Hello all, So I'm knee deep in this import utility program, and am coming up with all sorts of "gotcha's!". 1st off. On a "Find Duplicates Query", does anyone have a good solution for...
6
by: jsacrey | last post by:
Hey everybody, got a secnario for ya that I need a bit of help with. Access 97 using linked tables from an SQL Server 2000 machine. I've created a simple query using two tables joined by one...
2
by: existential.philosophy | last post by:
This is a new problem for me: I have some queries that open very slowly in design view. My benchmark query takes about 20 minutes to open in design view. That same query takes about 20 minutes...
9
by: Sinner | last post by:
Hi, I have a field name 'USER' in tableMAIN. How do I replace the user names with corresponding user names. I can do that in xl using vlookup but now I'm trying to find a way to do that in...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
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...

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.