subquery

How do I select min/max dates from table 2 based on date in table 1?

半腔热情 提交于 2019-12-10 12:28:40
问题 I have a monthly table (only holds rows with first day of month, and unique constraint so only one of each) and a daily table with similar information for each day (same deal, only one per day): Monthly table Daily table ------------- ----------- 2009-01-01 2009-01-01 2009-02-01 2009-01-02 : : : : 2009-09-01 2009-01-31 2009-02-01 : : 2009-02-28 2009-03-01 : : 2009-09-01 but there may be days missing. I want to run a query that returns, for each date in the monthly table, that date along with

Joomla 2.5 get all Ids of subcategories and do subselect in query

匆匆过客 提交于 2019-12-10 12:19:07
问题 I rack my brain with two hard nuts. Thus the problems are linked together I post them in one thread. Unfortunately I am not able to provide a Test Example. Here we go … I use following Query in my Joomla 2.5 template: ->select(array('a.description','a.display_name','a.parent_id','a.filename','a.url', 'b.title','b.alias', 'b.id','b.catid','b.state','c.title as catTitle','c.parent_id as catparent')) ->from('#__attachments AS a') ->join('LEFT', '#__content AS b ON (a.parent_id = b.id)') ->join(

Select a post that does not have a particular tag

倾然丶 夕夏残阳落幕 提交于 2019-12-10 11:57:11
问题 I have a post/tag database, with the usual post, tag, and tag_post tables. The tag_post table contains tagid and postid fields. I need to query posts. When I want to fetch posts that have a certain tag, I have to use a join: ... INNER JOIN tag_post ON post.id = tag_post.postid WHERE tag_post.tagid = {required_tagid}` When I want to fetch posts that have tagIdA and tagIdB, I have to use two joins (which I kind of came to terms with eventually). Now, I need to query posts that do not have a

Help with performance: SUBQUERY vs JOIN

末鹿安然 提交于 2019-12-10 11:53:50
问题 this is my problem: SUBQUERY 2.7 secs SELECT SQL_NO_CACHE item_id FROM mtrt_items_searches WHERE search_id IN ( SELECT SQL_NO_CACHE search_id FROM mtrt_searches_groups WHERE client_id =1 GROUP BY search_id ) LIMIT 0,350000 +----+--------------------+----------------------+-------+---------------+-----------+---------+-------+--------+--------------------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+--------------------+-----------------

Converting a self subquery to a self join

半世苍凉 提交于 2019-12-10 11:41:28
问题 I was wondering if there was a way to convert a self subquery to a self join Here is the self subquery SELECT a, b FROM c AS t1 WHERE ( b IN (SELECT b FROM c AS t2 WHERE ( t1.b = b ) AND ( t1.e <> e )) ) 回答1: If you only want to find the duplicates an EXIST would probably be faster: SELECT a,b FROM c WHERE EXISTS(SELECT NULL FROM c c2 WHERE c2.b=c.b AND c2.e<>c.e) If you want to join every record with its duplicate but get only one record for each: select t1.a , t1.b , t1.e as t1e , t2.e as

Join a Subquery with NHibernate

孤人 提交于 2019-12-10 11:08:48
问题 Is it possible to perform the following query in Criteria or QueryOver (NHibernate 3.1)? SELECT C.CustomerID, C.CustomerName, C.CustomerType, C.Address1, C.City, C.State, S.TotalSales FROM Customers C INNER JOIN (SELECT CustomerID, SUM(Sales) as TotalSales FROM Sales GROUP BY CustomerID) S ON C.CustomerID = S.CustomerID There was a similar question but it's quite old and was never answered. Maybe with the recent major updates from the NH team this can be answered! NHibernate 2.1: LEFT JOIN on

DataGridView cell search using a LINQ query

回眸只為那壹抹淺笑 提交于 2019-12-10 10:54:35
问题 I'm still relatively new to LINQ, and have done more stumbling around than anything, but I have really liked what I have seen so far. So with that in mind, I have a VB.NET search routine, part of which is provided, below, that checks all Text cells in a DataGridView for a given string (inclusive), using a basic set of nested loops to perform the search: ' Search for the first occurrence of the given string For Each row As DataGridViewRow In dgvMembers.Rows ' Skip the new row If row.IsNewRow

SQL Pagination Query with order by

江枫思渺然 提交于 2019-12-10 10:48:10
问题 I am trying to write a query that pulls multiple fields and assigns aliases to them. One of the aliases is actually a sum total of two fields. This is actually my biggest issue because that alias is one of the possible "fields" to sort by, or else I could just take out all of the aliases and not have this issue. Anyway, I need to be able to pass in a field in which to order by programmaticly. But because I need to do pagination with SQL, I cannot use the graceful function of LIMIT and have to

How to improve LIMIT clause in MySQL subquery?

烂漫一生 提交于 2019-12-10 10:38:46
问题 I have two tables : posts with 10k rows and comments and I need to select all comments for particular numbers of posts in other words implement the pagination by posts table and get all comments thereof. For that purpose I have the next query: select * from comments c inner join (select post_id from posts o order by post_id limit 0, 10) p on c.post_id = p.post_id; Also it is very important for me the performance of query. But the Explain of this query is very strange because LIMIT clause

How can I do this Spatial Query in Sql 2008?

百般思念 提交于 2019-12-10 10:38:22
问题 i'm trying to do a spatial query in sql 2008 -> for a given list of POI's (point of interest, long/lat GEOGRAPHY data), which postcodes do they exist in (multipolygon GEOGRAPHY data). So this is the query i tried, but it's syntactically incorrect:- SELECT PostCodeId, ShapeFile FROM Postcodes a WHERE a.ShapeFile.STIntersects( SELECT PointOfInterest FROM PointOfInterests WHERE PointOfInterestId IN (SELECT Item from dbo.fnSplit(@PoiIdList, ',')) So this means i pass in a csv list of POI Id's and