Symfony2 Doctrine query builder as a subquery in FROM clause
Tag : php , By : Julian Ivanov
Date : March 29 2020, 07:55 AM
wish of those help First off, subqueries in DQL is not possible. See Selecting from subquery in DQLSecondly, you are putting computed SQL from Doctrine Query Language (DQL) into a subquery. This does not work as the database cannot find the column due to DQL prefixing characters/numeric values to the columns.
|
Can I ORDER my results using a column returned from a subquery within a SELECT clause?
Tag : mysql , By : Ian Badcoe
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , Using the example below, which is not the exact code, just an example of what I'm trying to achieve: , Do this: SELECT temp.* FROM (SELECT
page_instance.name AS 'page name',
(
SELECT COUNT(*)
FROM visitor_event
WHERE page_instance.id = visitor_event.item_id
) AS 'visit_count'
FROM item_event
LEFT JOIN visitor_event_type ON visitor_event_type.id = visitor_event_type_id
LEFT JOIN page_instance ON page_instance.id = visitor_event.item_id
LEFT JOIN page ON page.id = page_instance.page_id
WHERE visitor_event_type.handle = 'viewed'
AND page_instance.name != 'NULL'
GROUP BY page.id
LIMIT 5 ) as temp ORDER BY temp.visit_count DESC
|
Use result of select column subquery in the where clause of the outer query?
Tag : sql , By : RinKaMan
Date : March 29 2020, 07:55 AM
Hope that helps I've got a table User and Company. The User records are a child of the Company records i.e. the User table has a column parent_company_id indicating which company the user is a part of. , There are many ways to do this. But one is to use cross apply: select c.name, j.james_count
from company c cross apply
(select count(*) as james_count
from [user] u
where first_name = 'James' and u.parent_company_id = company_id
) j
where james_count > 0;
select c.name, count(*) as james_count
from company c join
[user] u
on u.parent_company_id = c.company_id and u.first_name = 'James'
group by c.name;
|
SQL where clause to check if all selected column value is in a subquery select
Date : March 29 2020, 07:55 AM
may help you . If you want S_IDs all of whose items are in the second table, then use aggregation select t1.S_ID
from table1 t1
where t1.S_Type = 'TYPE' and
t1.item in (select t2.item from table2 t2)
group by S_ID
having count(distinct t1.item) = (select count(distinct t2.item) from table2 t2);
|
JOIN a table by SELECT subquery with LIMIT 1 and WHERE clause matching column values outside of it
Tag : mysql , By : Brianna
Date : March 29 2020, 07:55 AM
Does that help I'm trying to JOIN a table with a subquery to limit data to only 1 last row, matching certain values from other FROM or JOINed tables: , The solution for me was: SELECT
t1.column1,
t1.column2,
t2.column1,
t3.column2
FROM
table1 t1
JOIN table2 t2 ON t2.id =
(
SELECT id
FROM table2
WHERE t1.column2 > table2.column1
ORDER BY table2.date DESC
LIMIT 1
)
JOIN table3 t3 ON t2.column1=t3.column2
|