MySQL Match-Problem -> über mehrere Tabellen suchen
Bobby
- datenbank
Moin
ich habe 2 Tabellen mit je Name und Beschreibung als Spalten. Nun möchte ich mit einem Query beide Tabellen volltextsuchen
Mein Ansatz:
SELECT comtable.Name, comtable.Beschreibung
FROM
(
SELECT Tabelle1.Name AS Name, Tabelle1.Beschreibung AS Beschreibung
FROM Tabelle1
UNION
SELECT Tabelle2.Name AS Name, Tabelle2.Beschreibung AS Beschreibung
FROM Tabelle2
)
AS comtable
WHERE MATCH
(
Name, Beschreibung
)
AGAINST
(
'test'
)
So. Nun ist ja kein Volltextindex über die Spalten comtable.Name und comtable.Beschreibung gelegt was mir auch promt mit der Meldung _#1191 - Can't find FULLTEXT index matching the column list_ quittiert wird.
Wie bekomm ich das hin die Tabellen sinnvoll für eine Volltextsuche zu verknüpfen. Wo liegt mein Denkfehler?
Gruß Bobby
Moin
so. Hab die Abfrage nun mit Like gestaltet:
SELECT comtable.Typ, comtable.Name, comtable.Beschreibung
FROM
(
SELECT 'Tabelle1' AS Typ, Tabelle1.Name AS Name, Tabelle1.Beschreibung AS Beschreibung
FROM Tabelle1
UNION
SELECT 'Tabelle2' AS Typ, Tabelle2.Name AS Name, Tabelle2.Beschreibung AS Beschreibung
FROM Tabelle2
)
AS comtable
WHERE
comtable.Name LIKE '%test%'
OR
comtable.Beschreibung LIKE '%test%'
So funktionierts erstmal.
Wenn es eine elegantere Lösung mit der Fulltext-Funktionalität gibt, bitte ich darum. Man lernt ja nie aus
Gruß Bobby
Moin
Und nochmal ich: Sorry, aber ich will ja auch meine Lösungen mitteilen:
SELECT comtable.Typ, comtable.Name, comtable.Beschreibung
FROM
(
SELECT 'Tabelle1' AS Typ, Tabelle1.Name AS Name, Tabelle1.Beschreibung AS Beschreibung
FROM Tabelle1 WHERE MATCH (Name,Beschreibung) AGAINST ('test')
UNION
SELECT 'Tabelle2' AS Typ, Tabelle2.Name AS Name, Tabelle2.Beschreibung AS Beschreibung
FROM Tabelle2 WHERE MATCH (Name,Beschreibung) AGAINST ('test')
)
AS comtable
So funktionierts nun wie gewünscht. Gibts was dran auszusetzen?
Gruß Bobby