logo
Tags down

shadow

Mongodb query need improvement


By : Ulrik Kjær Rasmussen
Date : October 15 2020, 08:10 AM
wish help you to fix your issue Hello Everyone, , Simply use .dot notation with the _id
code :
db.users.aggregate([
  { "$lookup": {
    "from": "comments",
    "localField": "_id",
    "foreignField": "user_id",
    "as": "comment_ids"
  }},
  { "$addFields": { "comment_ids": "$comment_ids._id" }}
])


Share : facebook icon twitter icon

Is there an improvement for my sql query?


By : user2977942
Date : March 29 2020, 07:55 AM
hop of those help? What does the database tell you about your query? If id is indexed then
code :
mysql> explain select max(id) + 1 from times;
+----+-------------+-------+------+---------------+------+---------+------+------+------------------------------+
| id | select_type | table | type | possible_keys | key  | key_len | ref  | rows | Extra                        |
+----+-------------+-------+------+---------------+------+---------+------+------+------------------------------+
|  1 | SIMPLE      | NULL  | NULL | NULL          | NULL | NULL    | NULL | NULL | Select tables optimized away |
+----+-------------+-------+------+---------------+------+---------+------+------+------------------------------+
1 row in set (0.18 sec)

mysql> explain select id from times order by id ASC limit 1;
+----+-------------+-------+-------+---------------+---------+---------+------+------+-------------+
| id | select_type | table | type  | possible_keys | key     | key_len | ref  | rows | Extra       |
+----+-------------+-------+-------+---------------+---------+---------+------+------+-------------+
|  1 | SIMPLE      | times | index | NULL          | PRIMARY | 4       | NULL |    1 | Using index |
+----+-------------+-------+-------+---------------+---------+---------+------+------+-------------+
1 row in set (0.00 sec)

a query improvement


By : jasnooze
Date : March 29 2020, 07:55 AM
will be helpful for those in need Can somebody suggest me an improvement for the following query. , try this:
code :
SELECT     q.*
FROM       questions q
INNER JOIN answers a
ON         q.id = a.id_questions
WHERE      q.questions LIKE '%yourstring%'
OR         a.answers LIKE '%yourstring%'
GROUP BY   q.id

SQL query improvement


By : user2225597
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , First I'm going to rewrite your query with table aliases and proper join syntax:
code :
SELECT b.id, b.title, b.slug, b.source_id, b.thumb_url 
FROM books JOIN
     book_cat bc
     ON b.id = bc.book_id
WHERE bc.cat_id = 158 
ORDER BY b.id DESC
LIMIT 50;
SELECT b.id, b.title, b.slug, b.source_id, b.thumb_url 
FROM books
WHERE EXISTS (SELECT 1 FROM book_cat bc WHERE b.id = bc.book_id AND bc.cat_id = 158)
ORDER BY b.id DESC
LIMIT 50;

SQL query needs improvement


By : Veda
Date : March 29 2020, 07:55 AM
I wish this help you I think you are just missing a where on your subselect. You need to filter on classstudent where the StudentID=Student.StudentID:
code :
SELECT DISTINCT FIRSTNAME, LASTNAME FROM PERSON  
JOIN STUDENT ON PERSON.PERSONID = STUDENT.STUDENTID 
JOIN CLASSSTUDENT ON STUDENT.STUDENTID = CLASSSTUDENT.STUDENTID
WHERE STUDENT.YEARSTART > 2010
AND (SELECT AVG(FINALGRADE) 
    FROM CLASSSTUDENT
    WHERE FINALGRADE IS NOT NULL 
    AND FINALGRADE > 1
    AND STUDENTID=STUDENT.STUDENTID) >= 4.50;

SQL query - need improvement


By : András Zsolnai
Date : March 29 2020, 07:55 AM
it should still fix some issue One way is to remove the subquery and move the conditions closer to the tables:
shadow
Privacy Policy - Terms - Contact Us © voile276.org