MySql Query browers results - mysql

If you execute a query you get line that looks like this:
658 rows fetched in 0.0110s (0.0003s)
What does the numbers in parenthesis refer to?
I assume the 0.0110s is how long it took to run the query

Check out this response (as well as 2 replies to that):
http://forums.mysql.com/read.php?108,51989,210628#msg-210628
Maybe it will help

Related

Using Query to ignore covid return 0 results in newsapi

I am trying to ignore news from covid while querying news from newapi.org. And when I use the command to ignore a word "&q=-covid" I get 0 results. If I query for covid using "&q=covid" I get 2 results. And without any query, I get 38.
So when I ask it to ignore news that has covid in the name I should get 36 results and not 0.
Is this a bug or am I doing something wrong??
Here is the code:
https://newsapi.org/v2/top-headlines?country=us&apiKey=API_KEY&q=-covid
pls get new key from site
try removing "&q=-covid" or replacing the - with + to get full entries and entries with covid in the name.
Thanks for the help. Cheers!
All you need to do is add the query terms before the API key itself. Simply adjusting the placement of your q=-covid to the beginning of the query will do the trick.
So instead try this, here: https://newsapi.org/v2/everything?q=-covid&apiKey=660fe4700bd34641aa93bcc5b3ed38ee
If you're looking to make further adjustments to the cURL, this link to the NewsAPI documentation discusses how to utilize the query structure - which may be helpful: https://newsapi.org/docs/endpoints/everything

Multiple check in same column in Mysql

I have a table as below:
Here, I wanna run a query which looks like this:
SELECT model_id
FROM model_attributes
WHERE ((attributes_id=2 and attributes_value='32mb')) AND ((attributes_id=4 AND attributes_value='5.00 inch') OR (attributes_id=4 and attributes_value='6.00 inch')) AND ((attributes_id=5 and attributes_value='here') OR (attributes_id=5 and attributes_value='asfdsdf'))
which returns model_ids 8, 9. But it seems like I can't put multiple conditions in the same fields.
I also tried solutions in this post still nothing ! How can I get this result ? The way I used the AND clause is incorrect but resembles what logic I wanna implement in the query.
You are asking for rows where attributes_id is 2 and 4 and 5, that will never be true.
Try this:
WHERE (attributes_id=2 AND attributes_value='32mb') OR
(attributes_id=4 AND attributes_value in ('5.00 inch', '6.00 inch') OR
(attributes_id=5 AND attributes_valuein ('here', 'asfdsdf')
SELECT model_id
FROM model_attributes
WHERE ((attributes_id=2 and attributes_value='32mb')) or ((attributes_id=4 AND attributes_value='5.00 inch') OR (attributes_id=4 and attributes_value='6.00 inch')) or ((attributes_id=5 and attributes_value='here') OR (attributes_id=5 and attributes_value='asfdsdf'))
make and to orlike above i think and was logically wrong

How can I select certain rows that the key starts with a prefix in Hive?

A very simple question:
I wanted to select all the rows that their keys have a certain prefix in Hive, but somehow it's not working.
The queries I've tried:
select * from solr_json_history where dt='20170814' and hour='2147' and substr(`_root_`,1,9)='P10004232' limit 100;
SELECT * FROM solr_json_history where dt='20170814' and hour='2147' and `_root_` like 'P19746284%' limit 100;
My Hue editor just hangs there without returning anything.
I've checked this time range there's data in my table by this query:
select * from solr_json_history where dt='20170814' and hour='2147' limit 15;
It's returning 15 records as expected.
Any help please?
Thanks a lot!
Per #musafir-safwan's request, I've added it as an answer here.
UPDATE:
I'm not able to provide sample data. But my problem got resolved.
Thanks for the commentator's attention.
My table does have data, no need to worry about that. Thanks for checking though.
The problem was due to a bad Hue UI design, when I issued the above two queries, it takes too long (longer than the set timeout on the UI) to get a response back, so simply, the UI doesn't reply anything, or gives a timeout reminder. It just hangs there.
Also, those two queries essentially making two RPC calls, so they timed out.
Then I changed to use below query:
select `_root_`,json, count(*) from solr_json_history where dt='20170814' and hour='2147' and substr(`_root_`,1,9)='P19746284' group by `_root_`,json;
the difference is that I added a count(*) which turns this query into a map-reduce job thing, thus no timeout limit, and then it returns the result that I wanted.
YMMV.
Thanks.

Long query time

I have a query to post last 10 tv show episodes by sorting it by date (from newest to oldest) like this:
return $this->getEntityManager()->createQuery('SELECT t FROM AppBundle:TvShow t JOIN t.episodes e ORDER BY e.date DESC')->setFirstResult(0)->setMaxResults(10)->getResult();
It returns only 9 nine episode. We have similar queries in same page too, they are working fine. When i setMaxResults to (11) just then it returns 10 episodes.
Another issue related with this query is: it takes too long compared to other similar queries. (about 200ms)
What do you suggest for me?
Thanks in advance.
Like in Richard answer - wrong result with setMaxResults and fetch-joined collection is doctrine normal behaviour.
To make it works you can use Doctrine Pagination (from Doctrine 2.2) (docs: http://docs.doctrine-project.org/en/latest/tutorials/pagination.html)
Example usage:
use Doctrine\ORM\Tools\Pagination\Paginator;
$query->setMaxResults($limit);
$query->setFirstResult($offset);
$results = new Paginator($query, $fetchJoin = true);
Long query time looks like a topic for another question.
Straight from the documentation:
If your query contains a fetch-joined collection specifying the result limit methods are not working as you would expect. Set Max Results restricts the number of database result rows, however in the case of fetch-joined collections one root entity might appear in many rows, effectively hydrating less than the specified number of results.
https://doctrine-orm.readthedocs.org/en/latest/

Using HeidiSQL with mysql select statement with "not like" does not work

Ok guys, here's the story, I have a very simple query I'm trying to do and for the life of me I don't understand why it doesn't work.
I'm am using the streaming twitter feed to populate my database using keywords. Now I want to filter out the retweets by using this query
select * from earthquake
where earthquake.Text not like '%RT%'
order by earthquake.Text
It returns "0 rows affected, 0 rows found", and yes there are thousands of retweets, so I know they exist.
I do the same query with the '%#%' and it finds thousands as expected, it almost seems that everything except 'RT' works.
Did you try NOT LIKE '%RT #%'?
Is it possible that common word xxxrtxxx always contains in your Text field?
I don't know anything about mysql specifically, but is there a function like MSSQL's PatIndex() that you could use instead of not like?
Alternatively you could try something like this: (dont know if your db supports this syntax)
SELECT * FROM Earthquake
WHERE CASE WHEN Text LIKE '%RT%' THEN 1 ELSE 0 END = 0
ORDER BY Text
I'd also advise checking your logic of looking for "RT" somewhere in the Text column to identify the stuff you don't want, because I'm surprised that "Not Like [expression]" apparently doesnt work.