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

Searching 2 tables at once

3
Hi all,

I am facing an issue which I really don't know how to solve after googling for quite some time.

I have 2 tables: one is for my new articles and one is for the website content; I would like to build a search feature which would search both tables and return results from both. I considered using a union but there's a slight problem in that from the site content table I want information from one extra field...

site_content table fields:
ContentID INT(10),
Title VARCHAR(50),
Content TEXT,
Alias VARCHAR(30)

news_items table fields:
NewsID INT(10),
Title VARCHAR(50),
Content TEXT

Any ideas? It would be nice to order the results by relevance score (probably by full text searching) but that's not essential.
Aug 16 '07 #1
4 1432
code green
1,726 Expert 1GB
You have not specified a search criteria, but you could JOIN the tables.
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM `news_item`,`site_content`
  2. WHERE `list_of_fields_to_search` LIKE '%searchstring%'
Aug 16 '07 #2
I've been trying this as well...the Union doesn't work as I have 8 records in one table and 1 in the other that should return 9 results...Only getting 8 from the Union. Any guidance would kill 2 birds (myself & dodjem) with one stone! :)

Hi all,

I am facing an issue which I really don't know how to solve after googling for quite some time.

I have 2 tables: one is for my new articles and one is for the website content; I would like to build a search feature which would search both tables and return results from both. I considered using a union but there's a slight problem in that from the site content table I want information from one extra field...

site_content table fields:
ContentID INT(10),
Title VARCHAR(50),
Content TEXT,
Alias VARCHAR(30)

news_items table fields:
NewsID INT(10),
Title VARCHAR(50),
Content TEXT

Any ideas? It would be nice to order the results by relevance score (probably by full text searching) but that's not essential.
Aug 17 '07 #3
Sorry code green - I guess you were posting this as I was posting mine. I did use a search criteria in my Union and it didn't retrieve the records it should have. Can't use a join because I'm wanting records from both tables and even though the fields are the same names, there are different records in each table.

You have not specified a search criteria, but you could JOIN the tables.
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM `news_item`,`site_content`
  2. WHERE `list_of_fields_to_search` LIKE '%searchstring%'
Aug 17 '07 #4
I was using UNION ALL instead of just UNION....got the records I needed.

Thanks!!

Sorry code green - I guess you were posting this as I was posting mine. I did use a search criteria in my Union and it didn't retrieve the records it should have. Can't use a join because I'm wanting records from both tables and even though the fields are the same names, there are different records in each table.
Aug 17 '07 #5

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

Similar topics

1
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). ...
8
by: Stuart Clark | last post by:
Hello, I haven't done much with ASP but now I'm giving it a go! However, I'd like to ask if anybody knows if what I need to do is possible. I have a database with a lot of tables. Each table...
5
by: Ada | last post by:
hello folks, just wanna get some feedback from someone here who has more experience. :-) i'm developing a small app that require searching for the highest index within a directory. i was...
8
by: YunusEmre | last post by:
Hi, I have a class named MyDataAdapter that derives from System.ComponentModel.Component and it contains all of my SqlDataAdapter objects(around a 100). How can I find a SqlDataAdapter in the...
33
by: Geoff Jones | last post by:
Hiya I have a DataTable containing thousands of records. Each record has a primary key field called "ID" and another field called "PRODUCT" I want to retrieve the rows that satisy the following...
7
by: john | last post by:
In my form I have a master table and a details table linked 1xM. I can search through the whole parent table but I also like to be able to search through the child table fields to find parent...
5
by: Jerim79 | last post by:
I am trying to create a search system for an existing database. Because of the way the database is setup, I need to traverse three different tables, gathering information: 1) Go into table1 and...
5
by: jON Rowlan | last post by:
I am slowing get my head around the concept of treating tables as collections of rows as vb.net seems to prefer. However, I have an indexed table in an Access database that I want to scan. I...
12
by: Alexnb | last post by:
This is similar to my last post, but a little different. Here is what I would like to do. Lets say I have a text file. The contents look like this, only there is A LOT of the same thing. () A...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: 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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.