subquery

MySQL: subquerys OR unions?

跟風遠走 提交于 2019-12-12 06:50:45
问题 I do not explain the logic of the query , because it is not simple. If I explain in detail - no one will want to read and delve into the essence of the query. There are two querys. They do their job well. Result: identical. Checked in manual mode, with a pencil on paper (and on a data base). Which query will less load the server? Or will it only be found out some time after working on a real (production) server? The operation UNION veryhard load the server? What should I look for in the

How to use field from subquery in MySQL?

自古美人都是妖i 提交于 2019-12-12 06:39:05
问题 I've got the following query: SELECT insent.id, notifications.id FROM insent WHERE insent.id IN ( SELECT insent_id FROM notifications ) ; But this gives an error saying: Unknown column 'notifications.id' in 'field list' Any idea how I can do this? 回答1: If you want to get data from few tables in one query then you should use JOIN construction. For example: SELECT insent.id, notifications.id FROM insent JOIN notifications ON notifications.insent_id = insent.id if you don't want it you must

How to limit a subquery in cypher?

寵の児 提交于 2019-12-12 06:06:53
问题 Say I have 3 things in my graph database and each of these 3 things have 0 or more subthings attached to them. How do I make a query to retrieve the top 2 subthings for each of the things in the graph (according to some arbitrary ordering). Here's an example setup: CREATE (t1:Thing)-[:X]->(a1:SubThing), (t1)-[:X]->(a2:SubThing), (t1)-[:X]->(a3:SubThing), (t1)-[:X]->(a4:SubThing), (t2:Thing)-[:X]->(b1:SubThing), (t2)-[:X]->(b2:SubThing), (t2)-[:X]->(b3:SubThing), (t3:Thing); What match command

ERROR: more than one row returned by a subquery used as an expression

允我心安 提交于 2019-12-12 05:36:11
问题 I have searched and searched.. I have a bash script that is used to run a psql query and email the results on a daily basis. The DB does not update till midnight and my bash script passes a variable to the query for the day prior. I am getting this error only when I use the passed variable otherwise if I put the date in the query manually it runs fine. Not quite sure for I am still learning psql and bash. Here is the bash script: #!/bin/bash NOWDATE=`date +%Y-%m-%d -d "yesterday"` SUBDATE=

Mixed MySQL and Sphinx queries

送分小仙女□ 提交于 2019-12-12 05:25:12
问题 I have MySQL and Sphinx installed and working properly on a LNMP server. Now I'd like to integrate a Sphinx sub-query into an existing MySQL query. Example: SELECT * FROM mysql_table JOIN (SELECT id FROM sphinx_index MATCH ('keyword')) AS match_table ON match_table.id = mysql_table.id Is this possible? If not, should I do the Sphinx separately and then use WHERE IN in the MySQL query, or will this kill the extra efficiency I'm getting from Sphinx? 回答1: Use SphinxSE http://sphinxsearch.com

MySql update with subselect

让人想犯罪 __ 提交于 2019-12-12 05:15:53
问题 I have a mysql database table where there is an email column which can contain up to two emails separated by an semicolon. What i want to achieve is write the second email address in the email field into another column email2 This is what I tried so far without success: UPDATE user AS u SET email2 = (SELECT SUBSTRING_INDEX(email, ';', -1) FROM user WHERE user.id=u.id) WHERE username LIKE "%;%" When searching for this problems there were some solutions unsing a second subquery within the

Using a Subquery in the Against for a FULLTEXT search in Mysql

陌路散爱 提交于 2019-12-12 04:45:01
问题 In MySQL, I would like to do a FULLTEXT search on a table 'articles'. The text I want to search against would be located in another table, 'Vectors' under the column 'CVs' I am trying: SELECT website FROM articles WHERE MATCH (title, body) AGAINST( SELECT CVs FROM Vectors WHERE Title="cv1") However, it keeps returning syntax error. Is it possible to run a subquery in the AGAINST clause? 回答1: You would like to be able to do: SELECT website FROM articles cross join vectors WHERE title = 'cv1'

Only return an ordered subset of the rows from a joined table

爷,独闯天下 提交于 2019-12-12 04:18:02
问题 Given a structure like this in a MySQL database #data_table (id) | user_id | time | (...) #relations_table (id) | user_id | user_coach_id | (...) we can select all data_table rows belonging to a certain user_coach_id (let's say 1) with SELECT rel.`user_coach_id`, dat.* FROM `relations_table` rel LEFT JOIN `data_table` dat ON rel.`uid` = dat.`uid` WHERE rel.`user_coach_id` = 1 ORDER BY val.`time` DESC returning something like | user_coach_id | id | user_id | time | data1 | data2 | ... | 1 | 9

Place an Insert Statement into a Select Statement

牧云@^-^@ 提交于 2019-12-12 04:07:00
问题 I have read the other questions and all of the posted comments/answers to questions that are similar to this one. None of them seem to answer this question directly. I am wanting to know if there is a way to either concatenate or place an INSERT , DELETE or UPDATE statement into a SELECT statement. If so how? Could this be done by using a derived table function or a subSelect statement? And example would be: INSERT INTO Customer (name) VALUES 'Test Name' but place this into a SELECT statement

“Union Operation not allowed in sub query” is there a way to fix this in one single query?

只愿长相守 提交于 2019-12-12 03:52:43
问题 This Query Dose NOT work in Access 2000 SELECT (Members.First_Name + " " + Members.Last_Name)AS Member, (SELECT Friend_E_Mail, FROM Friends,Members WHERE My_E_Mail = ? and Friend_E_Mail <> ? UNION ALL SELECT My_E_Mail,FROM Friends,Members WHERE Friend_E_Mail = ?and My_E_Mail <> ?) AS E_Mail , (Members.First_Name) AS Name FROM Members,Friends Sample Tables Members(all VARCHAR) SOME DATA First_Name Alester Jude Carl Jones Last_Name A B C J FRIENDS(ALL VARCHAR) My_E_Mail Alester@lam.com Alester