Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options answers only not deleted user 110455

SQL term used to describe when a `SELECT` statement is used as part of a larger SQL statement. The larger statement may be DML and is always found within brackets or parenthesis.

2 votes
Accepted

Count up number of rows matching criteria in same table

Using GROUP BY should avoid to use the subquery. SELECT link_id_fk, COUNT(*) AS total FROM lsql_Flex_Values flex WHERE flex_type = 'address' GROUP BY link_id_fk; …
McNets's user avatar
  • 23.9k
0 votes
Accepted

Join or Replace colum value based on query

You can use an scalar subquery in this way: SELECT h.name, i.name, i.delay, i.delay_flex, i.status, (SELECT name FROM hosts …
McNets's user avatar
  • 23.9k
0 votes

How to query with the condition with subquery

It is not clear what you are asking for, but maybe this solve your problem. select * from table_A as a inner join table_B as b on a.sass = b.sass where a.id = 1 and b.condition = 'somet …
McNets's user avatar
  • 23.9k
2 votes

user parent table id in nested subquery

You should move your WHERE user_id = users.id clause to the first correlated subquery. …
McNets's user avatar
  • 23.9k
1 vote
Accepted

Why does `row_to_json(...)` accept a sub-query?

Let me select some records from tbl: SELECT id, title FROM tbl; id | title -: | :------ 1 | Title 1 2 | Title 2 3 | Title 3 Now using a subquery: SELECT * FROM (SELECT id, title FROM tbl) t; …
McNets's user avatar
  • 23.9k
0 votes
Accepted

unable to add limit to the subquery

select i.id, i.name, i.description, s.quantity stock, (select purchaseRate from itemPurchaseDetail where item_id = i.id order b …
McNets's user avatar
  • 23.9k
1 vote
Accepted

Update rows in table with id from row before in PostgreSQL

You can get your desired result by using LAG() function. select id, grp, time_added, lag(id) over (partition by grp order by grp, time_added) previous_id from tbl; You can updat …
McNets's user avatar
  • 23.9k
1 vote
Accepted

Count total number of nested one to many relationships

Let me know if this covers your desired result. create table users (user_id int primary key, name varchar(20)); insert into users values(1, 'john'), (2, 'anne'), (3, 'peter'); create table costs( …
McNets's user avatar
  • 23.9k
1 vote

Trying to run query and getting error: Error 1064 (42000)

select flwusertest_users.ID, flwusertest_users.display_name, flwusertest_users.user_email from flwusertest_users INNER JOIN flwusertest_usermeta ON flwu …
McNets's user avatar
  • 23.9k
1 vote
Accepted

How to filters data with two windows conditions?

You can use EXIST in WHERE clause: Adding both conditions, must exists at least one access with door and must exists one access without. select u.id, a.door_id, d.type from users u left join …
McNets's user avatar
  • 23.9k
1 vote
Accepted

How to query Wikipedia's database to retrieve the main topic and the surface forms of a give...

Initially it seems pretty easy to solve the question, by adding a new criteria to the WHERE clause. SELECT page.page_id, page.page_title, redirect.rd_from, redirect.rd_title FROM …
McNets's user avatar
  • 23.9k
0 votes
Accepted

Insert Into with Select works in once instance, but not the other. Subquery error or incorre...

I'll start after you has generated #SurveyTemp table. I'm not sure to understand your expected result, take a look at your table ordered by demo: SELECT * FROM @table_survey WHERE demo I …
McNets's user avatar
  • 23.9k
4 votes

MySQL LIMIT within JOIN

For a correlated subquery you should use a CROSS APPLY, unfortunately MySql doesn't allow it, but you can simulate it on this way: SELECT `symbols`.`id`, `symbols`. …
McNets's user avatar
  • 23.9k
6 votes

how to add loop in date column in sql through query?

You can use a calendar table: CREATE TABLE Calendar(cDate datetime, cDay int, cDayOfWeek int, cDayName varchar(20), cMonth int); DECLARE @date date = '20180101'; WHILE @date <= '20180131' BEGIN …
McNets's user avatar
  • 23.9k