Questions tagged [querying]

516 questions
501
votes
3 answers

Nested select statement in SQL Server

Why doesn't the following work? SELECT name FROM (SELECT name FROM agentinformation) I guess my understanding of SQL is wrong, because I would have thought this would return the same thing as SELECT name FROM agentinformation Doesn't the inner…
Brennan Vincent
  • 10,736
  • 9
  • 32
  • 54
260
votes
27 answers

Is there a query language for JSON?

Is there a (roughly) SQL or XQuery-like language for querying JSON? I'm thinking of very small datasets that map nicely to JSON where it would be nice to easily answer queries such as "what are all the values of X where Y > 3" or to do the usual SUM…
allclaws
  • 5,575
  • 8
  • 30
  • 27
60
votes
11 answers

Query a single document from Firestore in Flutter (cloud_firestore Plugin)

Edit: This Question is outdated, and I am sure, new documentation and more recent answers are available as of now. I want to retrieve data of only a single document via its ID. My approach with example data of: TESTID1 { 'name': 'example', …
blandaadrian
  • 742
  • 1
  • 5
  • 16
27
votes
3 answers

Querying array elements with Mongo

How can I query the smoothies that have apple in them? (below is a collection with 3 documents) _id => 1 name => 'best smoothie' ingredients => Array ( [0] => apple [1] => raspberry [2] => orange [3] => banana …
Devrim
  • 2,826
  • 5
  • 25
  • 31
25
votes
3 answers

Eager loading child collection with NHibernate

I want to load root entities and eager load all it's child collection and aggregate members. Have been trying to use the SetFetchMode in FluentNHibernate, but I am getting duplicates in one of the child collection since I have a depth of 3 levels.…
Kristoffer
  • 1,633
  • 3
  • 19
  • 25
23
votes
3 answers

Efficient pagination and database querying in django

There were some code examples for django pagination which I used a while back. I may be wrong but when looking over the code it looks like it wastes tons of memory. I was looking for a better solution, here is the code: # in views.py from…
Lucas Ou-Yang
  • 5,505
  • 13
  • 43
  • 62
16
votes
6 answers

PHP and MySQL: Order by most recent date and limit 10

I am building a notes system on my site and I've got to the stage where users can post notes into the MySQL database using PHP and then PHP prints them out on a page. However, when they print/echo out, the oldest one appears first but I want the…
James
  • 576
  • 2
  • 8
  • 20
13
votes
2 answers

SQLAlchemy: several counts in one query

I am having hard time optimizing my SQLAlchemy queries. My SQL knowledge is very basic, and I just can't get the stuff I need from the SQLAlchemy docs. Suppose the following very basic one-to-many relationship: class Parent(Base): __tablename__…
kreo
  • 2,613
  • 2
  • 19
  • 31
13
votes
2 answers

MongoDB/PyMongo: Querying multiple criteria - unexpected results

I have a collection where some of the objects feature an key foo. I now try to query for all objects that indeed have this key but not with the specific value bar. For this I use the following query: collection.find({'foo': {'$exists': True}, 'foo':…
Christian
  • 3,239
  • 5
  • 38
  • 79
11
votes
1 answer

Elasticsearch match phrase prefix not matching all terms

I am having an issue where when I use the match_phrase_prefix query in Elasticsearch, it is not returning all the results I would expect it to, particularly when the query is one word followed by one letter. Take this index mapping (this is a…
Paul T Davies
  • 2,527
  • 2
  • 22
  • 39
10
votes
4 answers

How fast is it to look up by ObjectId in Mongodb?

I'm looking up ObjectIds everywhere, as if they're cake. Is this OK? _id fields are supposed to be looked up like crazy, right?
TIMEX
  • 259,804
  • 351
  • 777
  • 1,080
10
votes
4 answers

MongoDB: how to find documents ignoring case sensitive, accents and percent like logic (%)

I would like to make a search on a collection in my mongodb database. In my collection, I have documents with the field "name" can be values like: [i] "Palácio Guanabara", "Palácio da Cidade", "Festa Palácio", etc. When a user types a search like…
9
votes
2 answers

Is it possible to get contents of copy_to field in Elasticsearch?

I'm using Elasticsearch v2.3.0. Suppose I have an index with mapping: { "mappings": { "post": { "dynamic": false, "_source": { "enabled": true }, "properties": { "text": { "norms": { "enabled": false …
ov7a
  • 1,497
  • 4
  • 15
  • 34
8
votes
2 answers

MongoDB Querying for object property in list

Let's say I do have a document like this: { _id: "cow", comments: [ {user: "karl", comment: "I like cows.", at: /*a date*/}, {user: "harry", comment: "Cows are the best.", at: /*a date*/} ] } Now I want to collect all…
Lanbo
  • 15,118
  • 16
  • 70
  • 147
7
votes
4 answers

MongoDB : use $ positional operator for querying

I have a collection with entries that look like : { "userid": 1, "contents": [ { "tag": "whatever", "value": 100 }, {"tag": "whatever2", "value": 110 } ] } I'd like to be able to query on that collection…
Johanisma
  • 2,058
  • 3
  • 22
  • 25
1
2 3
34 35