Mysql Query Help to compare multiple urls - mysql

I have a db with 14k links, im trying to find each url that is in the db twice or more.
Using this query below I'am able to strip them down to simple url's.
SELECT SUBSTRING_INDEX(url,'/',3) FROM Links WHERE url REGEXP '^[^:]+://';
I'm looking for help in now taking the results and counting them to present a list of all the domains that have 2 or more entries in my DB:

Once you strip down all the URLs to their simple form you can use the following query to find the no. of counts of the URLs appearing in the db.
SELECT *
FROM `Links`
GROUP BY url(`url`)
HAVING COUNT(*) > 1

Related

MySQL query to fetch this data in Wordpress

I'm not very good with MySQL queries, I'm looking to fetch the columns from multiple data using MySQL query. Considering DB name is "db_name" and prefix is like "wp_",
post_name
post_title
post_content
featured image url
categories
tag
Can I fetch this stuff in a single query or I have to use multiple queries? The categories and tags are the ones that would be associated with a given post. Any help would be appreciated.
Thanks!

How to group table rows based on hash present in table column

I am using ahoy gem in rails application to get the analytics data which is present in ahoy_events table i want to group the rows based on the id present in hash of properties column.
Table looks like this https://s10.postimg.org/j9e5ylvuh/data_table.png
Have tried query like Ahoy::Event.group("properties REGEXP '[{,]\"id\"[,}]' ") this returns only the first row.I know the syntax is correct but i am unable to find where i am getting wrong.Have search it a lot and tried different combination permutations of queries but could not find the correct one.Any suggesstions will be a great help.

MySQL Search Query for WordPress Database

I am currently building a mobile(Android) app that is a search engine for products. The products information, is currently stored in a WordPress eCommerce store(WooCommerce). I have added 5 sample products to this store for testing purposes.
I currently have the search function working inside the app. The MySQL query used for this search is as follows:
SELECT a.*, b.guid AS img_url
FROM wp_posts AS a
LEFT JOIN wp_posts AS b ON a.ID = b.post_parent
WHERE a.post_type='product'
AND a.post_title LIKE '%$search%'
Now, when I search for something like "sample", I get my search results with all of the products that contain the word sample in it's title.
However, if one of those products has more than one image attached to it. I get results for as many images that are attached to the product.(see screenshot below)
Screenshot: http://cl.ly/M7Ap
If anyone could help me with this, so that I don't get the multiple results for the one post. It would be greatly appreciated.
If you don't care about which result, but just want one per post, can you not just use GROUP BY?

Search page engine PHP with MYSQL database?

I'm going to generalize this question so that other people can use the answers.
Let's say I have a website driven by a MYSQL database.
Database contains 5 tables:events,news,books,articles,tips.
Every table has among others 2 fields Title and Details in which I want to search
On every page of the site I have a search form (text field and button).
After I type a word or phrase I want to be redirected to a page called search where I should see the results as a list with links from the entire database.
e.g.
Book X (link on it to the book found in the database)
Event Y
Article Z
HELP: The tables are INNODB ENGINE so full text search didn't work also I'm having trouble in building a SELECT statement for searching multiple fields from multiple tables with LIKE. I've succeded with one table but with multiple tables and multiple fields I'm getting error or no data or duplicated data in some cases. Some help with this Select statement please.
Question: How do I build a search engine for all the tables in my MYSQL DB? Some SQL injection or other hacking prevention advice would be appreciated also.
My Approach to the situation is create a view based on all the tables with similar columns ( columns which we need to search only) and one more alias column with their table names/ entity name (Books, event etc)
It should look like this
EntityName Title Details
Books xxxx xxxxx
...............................
I am not explaining how to create views with union (dont use Union All if not expecting duplicates).
The next stop would be search using like statements
select * from vwSearchData where Title like '%keyword' or details like '%keyword'
Next step is to display the data along with their entity names.
Ofcourse, you need to get the keyword by filtering with html entities from the search form.
You can use UNION:
(SELECT * FROM events WHERE title LIKE '$key' OR details LIKE '$key')
UNION
(SELECT * FROM news WHERE title LIKE '$key' OR details LIKE '$key')
and so on.

How to extract relevant data from MySQL?

I'm using a table named "url2" with tje MySQL InnoDB Engine. I'm having so many data with full HTML of a Page, URL of the page, and so on.... When I use the following SQL query I am getting lot of results:
SELECT url FROM url2 WHERE html LIKE '%Yuva%' OR url LIKE '%Yuva%'
The search term yuva can be changes as user request
It will select lot of data, mostly which I don't need, how can i avoid that?
The out put of the above query is
www.123musiq.com
www.123musiq.com/home.html
www.123musiq.com/yuva.html
www.sensongs.com/
www.sensongs.com/hindi.html
www.sensongs.com/yuva.html
The Output i need is
According to the relevancy it should be sorted Like
www.123musiq.com/yuva.html
www.sensongs.com/yuva.html
www.sensongs.com/hindi.html
As from the comment of my Friend i change table to MyISAM,but i am geting 123musiq.com files first about 25 after that i am geting sensongs.how can i get 2 from 123musiq.com and 2 from sensongs.com,order by relevance
It seems you're asking for a Full Text Index, which in MySQL are only available on MyISAM tables.
Since you're using InnoDB tables, the easiest solution is to create a new (MyISAM) table with only the text content and an index to join with the original table (this also helps with seek efficiency in some common cases).
Perhaps you want to use LIMIT?
SELECT * FROM url2 WHERE html LIKE '%Yuva%' OR url LIKE '%Yuva%' LIMIT 2