I want to do the same[ on logic ] as this question -> SQL/mysql - Select distinct/UNIQUE but return all columns?
Using SELECT DISTINCT PATH FROM...
instead of SELECT * FROM
doesn't returns duplicates [ UNION
works ] but it does return only one table column [PATH
] , i want all the columns of the tables not only the Path
column .
**Basically what i want to do is sql select multiple columns with only one distinct column
** the column PATH
Here is the SQLITE3 db file ->https://github.com/goxr3plus/Tester
Example sql statements for the db :
SELECT * FROM '_44057' UNION SELECT * FROM '_76468' UNION SELECT * FROM '_25912' UNION SELECT * FROM '_12603' WHERE PATH LIKE '%e%';
SELECT * FROM '_44057' UNION SELECT * FROM '_76468' UNION SELECT * FROM '_25912' UNION SELECT * FROM '_12603' WHERE PATH LIKE '%e%' GROUP BY PATH;
I am using
SQLITE
and i have 4 same tables with the same data and colums . So the tables contains the columns (PATH->this is primary key,STARS,...).
Actually here is the Table create statement :
"CREATE TABLE '" + dataBaseTableName + "'"
+ "(PATH TEXT PRIMARY KEY NOT NULL ,"
+ "STARS DOUBLE NOT NULL,"
+ "TIMESPLAYED INT NOT NULL,"
+ "DATE TEXT NOT NULL,"
+ "HOUR TEXT NOT NULL)");
What i want to do is search for those items-songs that contain the specific word , for example a
.
So i am using UNION
to collect all the tables data and finally a WHERE
STATEMENT with a LIKE
, finally i limit my results to 50. I also don't want dublicates but for some reason i am getting duplicate rows ...
- The problems:
1)Dublicate rows are being returned
2)When tables contains a lot of elements it is getting slow
- Small Explanation for code below:
- Where you can see
'%" + word + "%'
, word is aString
for examplea
- The below SQL Statement is dynamically generated , i mean that i can have more that 4 tables and each table can contain thousands of songs [ That makes the query very slow sometimes )
Simple SQL code:
SELECT * FROM '_44057'
UNION
SELECT * FROM '_76468'
UNION
SELECT * FROM '_25912'
UNION
SELECT * FROM '_12603'
WHERE PATH LIKE '%" + word + "%' LIMIT 50
Finally:
Any recommendation , i mean anything from LIKE
to Select
or UNION
replacing is appreciated a lot cause i am new to this :).
Image from Duplicate rows: