DO NOT USE this for questions targeting Microsoft SQL Server, use the tag sql-server instead. "SQL" is an acronym for "Structured Query Language", it is used in relational database management systems (RDBMS) to query, update, delete, and insert data as well as modify the structure of the database. ...

learn more… | top users | synonyms (1)

1
vote
1answer
43 views

Combining data from 3 tables depending values stored in 1 table

I'm trying to make a SQL query to return values potentially from 3 tables. This will combine all booking information for a booking which can span over multiple days with multiple guests and a single ...
0
votes
1answer
69 views

Cross Join and Left Join within a query

I have query which has a cross join and also a left join which produces an error Unknown column 'a.hour' in 'on clause' simplified version of query is like this SELECT b.*,a.hour,c.datetime FROM ...
1
vote
1answer
22 views

UPDATE with Nested Query

This is what i've tried UPDATE (SELECT * FROM music GROUP BY songalbum) SET albumID = (SELECT albumID FROM albumList GROUP BY album ) WHERE songalbum = albumList.album this give the error #1248 ...
2
votes
1answer
60 views

How to optimize this MySQL query?

Hi can someone help me to optimize this MySQL query, it's taking very long to complete, I have set indexes correctly, but it seems that string operations are slowing this query SELECT ...
0
votes
0answers
27 views

Problem forming a query with subqueries in design view? (MS Access 2010)?

I just started a new job as a dbase admin intern, and due to the database being very large, it is better to do queries in design view, rather than hardcoding the sql. That being said, I cant seem to ...
1
vote
0answers
34 views

How does 'exists' affect output

I previously asked a question about how to organize a long search query. I have taken it apart. I am presently attempting to understand the function of some of its parts. Specifically, I am ...
4
votes
1answer
80 views

Query Plans Change Performance Worse in SQL Server 2014

We recently upgraded our server from SQL Server 2008R2 to SQL Server 2014. We have a query that ran fine in 2008R2 but now in 2014 runs incredibly much slower and has a bad execution plan. I've done ...
0
votes
1answer
63 views

Problem with UNION ALL

I have to process 200 points (lat, long) to calculate the minor distance of same object (street in this case). So, I made a simple query to obtain 1 result, and replicate the same to the other 199. ...
0
votes
1answer
54 views

SQL Developer - trying to import an excel file into a table

I'm trying to import an excel file into a table. The excel file has dates in the following format: 20/08/2008 12:00:00 AM and I am telling SQLDEV the following: DD/MM/YYYY H24:MI:SS AM To import the ...
0
votes
1answer
61 views

Error using view to limit data access between databases in SQL Server [duplicate]

I am trying to limit user access to data through a view. I have a database full of replicated data that I do not want the users to be able to access, I also have a reporting database in which I will ...
-5
votes
1answer
106 views

How to select only few columns from a table in database? [closed]

I have a table which consists of around 200 columns where name of each one is col_i (i=1 ,2,..200).Suppose I have to select only first 50 columns, how should I proceed? I found about concat() function ...
1
vote
1answer
28 views

Data type and Operator type Errors

i am following learn sql the hard way tutorial, in tutorial tutor suggest to use sqllite 3 but im using MSSQL 2008 and i have a problem, tutor ask from me to find something using AND or OR operators, ...
1
vote
1answer
28 views

Problem passing rows results to columns names

I have a table with following data: ID IDALUMNO ALUMNO IDTIPOEVALUACION TIPOEVALUACION NOTA 1 682 ALVITEZ MIRANDA, KAREN LIZET 1 PR1 ...
-1
votes
2answers
50 views

Getting a total value for items obtained in the current quarter

I've been working with MS SQL Server Management Studio and have a problem I can't fix. I am currently able to get the total for a set of values (Volume and Activity) from my SQL Server database. ...
0
votes
2answers
53 views

Count of distinct values of a table using sql

name number ============= lin | 8 lin | 8 lin | 8 rob | 8 rob | 8 rob | 8 lin | 8 lin | 41 lin | 41 rob | 41 and I want the result like name | Count of 8 | count of 41 ...
0
votes
0answers
32 views

No data transferred when trying to transfer columns from one database to another [closed]

I'm trying to transfer columns from one database to another using the following: INSERT INTO ykz2d_purchas_integration (name, amount, summary) SELECT user_email, orderpayment_amount, ...
0
votes
1answer
70 views

How to organize long Query

I have a massive query string that I am trying to pick apart for a project I am working on. I am looking for some guidance on how to take it apart(format it into human readable). Also, what are the ...
2
votes
1answer
83 views

How to select from 3 tables while using count on 1, and sum on another?

I'm stuck on this one query. Here is my setup: table 1 (shows) show_user show_count table 2 (views) view_user view_views table 3 (users) user user_name What I need to is produce results ...
0
votes
0answers
12 views

Truncate log file mirrored database [duplicate]

In SQL Server 2008, I have a mirrored database with a log file that has increased to 80GB, which is not normal and I have serious problem. I would like to decrease the log file size by truncating it. ...
2
votes
1answer
66 views

Exclusively access a table and prevent other queries, even read queries

I'm stuck at setting transaction isolation level. Here's my scenario that happens in the application: Get unprocessed messages (using the IsProcessing flag) Set their IsProcessing to true (in RAM) ...
-1
votes
0answers
28 views

connection string of datasource in report manager is different in regard to ReportServer database

I have an SSRS/SQL Server problem. I wrote query to get table with reportName, datasourceName, connection_string from Catalog table in ReportServer database. I get 600 rows with correct data, but in ...
0
votes
0answers
37 views

Reduce SORT overhead / Improve order by performance

My business works like this: The client downloads the data from this table which contains roughly 33 millions rows holding one week worth of data (which is then moved to a historic table). The client ...
-1
votes
0answers
37 views

Get available first booking date in my system

I am creating an application which connects users with workers. Users are those who have some requests to be done and Workers are those who works for the users and get paid based on the working time. ...
3
votes
3answers
144 views

Optimizing a query which runs through all hours in a day

I need help optimizing a query. I'm using PostgreSQL 9.3.4 currently but can upgrade to 9.4 if needed. I have a table with 60+ millions of records which looks like this: ...
1
vote
1answer
41 views

select members with the longest running absence streak

I have a database containing a table that stores attendance data, and its columns are member_id and datetime_attended. And another table storing members info, which is made up by the columns id and ...
0
votes
0answers
26 views

How can I set a value after Select query in PostgreSQL? [migrated]

I use simple select query: SELECT transactiontype FROM posfeed LIMIT 100; I result I have some rows with empty values. I need set some default value in SELECT query result for some filed. ...
2
votes
2answers
69 views

Ensure order when select two rows using two identifiers on the same column

I'm trying to writing a query to retrieve exactly two rows from a table using the same column for indentification. SELECT * FROM teams WHERE name = $1 OR name = $2; Is there any way to ensure that ...
0
votes
1answer
25 views

Naming a second additional column referencing another table column?

I'm working with a table in database that references to a column in another table. Such as: Product Table ------------ Id Description Currencies_Code Currencies ------------ Id Code Description ...
0
votes
2answers
86 views

Why does my SQL Server Express (2014) connection break after restarting my computer?

For some reason when I install SQL Server Express (2014), it works fine for a while (usually a day or two), and then quits allowing me to sign in. I'm not just talking about remotely here, either. ...
0
votes
1answer
23 views

Possible to use a field within a query in PostgreSQL?

I want to query all events that are going on right now. Each events record has at and minutes fields for the time range of the event. I might query the events table like this: SELECT * FROM events ...
0
votes
1answer
44 views

What is the purpose of the keyword “||” in PostgreSQL? [closed]

I'm new to PostgreSQL and I'm trying to figure out what does the operator || mean? Google didn't help with that...
0
votes
1answer
23 views

Postgresql select columns in join query [closed]

say that i do inner join in query... the result will give columns from both table. Is there a way to specify that i want only columns from one of the tables without specifying all columns names ...
1
vote
1answer
34 views

How to update table1 field by using other table and function

I have two tables and one function: Table1 contains shop_code,batch_id shop_code| batch_id | regstriy_id 123 | 100 | 12 124 | 100 |13 125 | 100 |12 Table2 contains shop_code,shop_name ...
3
votes
1answer
51 views

DBCC CHECKDB Estimation Alternative

I am in the process of rolling out DBCC CHECKDB across our instances. Each database will eventually either have a DBCC CHECKDB or DBCC CHECKDB PHYSICAL_ONLY. The way I have been gauging whether a ...
0
votes
0answers
17 views

Postgresql list all functions associated with table and column [duplicate]

I have a table named SW and in it a column named ID. I want to list all functions from all Schemas that use this table and this column. I've wrote the following query: SELECT n.nspname AS ...
0
votes
0answers
26 views

Running recursive Merge in SQL server

I just realized, I should have added it here in dba.StackExchange, instead of Stackoverflow, so apologies for the duplication I have two tables, a Card with a list of CardLines associated to it Card ...
0
votes
0answers
11 views

How do I use a SP in SQL Server 2014 to call a external XML source?

I am attempting to retrieve Currency Exchange rates from http://www.floatrates.com/daily/usd.xml using a SP in SQL Server 2014. The result is in XML. So I created the following SProc: --DROP ...
-1
votes
1answer
32 views

how to aggregate time and data correspondingly using SQL?

I want to aggregate the time series and the data under each time series, the table I have now is: 00:00,00:15,location_1,300 00:00,00:15,location_2,240 00:15,00:30,location_1,100 ...
0
votes
0answers
10 views

Query table with the same name on different schemas in PostgreSQL [duplicate]

I want to query table with the same name (for instances "walls") in multiple schemas on a PostgreSQL database. Is it possible? I am searching for something like this: select * from *.walls; I need ...
0
votes
0answers
36 views

How to list all tables associated with specific foreign key?

I have this Postgresql query: select (select r.relname from pg_class r where r.oid = c.conrelid) as table, (select r.relkind from pg_class r where r.oid = c.conrelid) as type, (select ...
0
votes
1answer
48 views

Check for duplicates in column and determine which row to keep

I've found myself running in to this on multiple occasions now where I got a query and would need too further refine it. Where one column might contain duplicates and I need to evaluate which row to ...
0
votes
4answers
40 views

The multi-part identifier > “a.surveyid” could not be bound [closed]

I am getting the error : Msg 4104, Level 16, State 1, Line 1 The multi-part identifier "a.surveyid" could not be bound. Below is the query ,what could be the issue? SELECT a.surveyid,* ...
0
votes
0answers
23 views

postgresql view all tables with specific FK

I have a table of suppliers with supplierID (PK) and supplierName in Schema X I want to find out all tables names in all Schemas where the supplierID is FK there. How can i write a query that does ...
1
vote
3answers
170 views

Select using values from another table

I want to select specific columns from a table, let's say table A. Table B has the names of the names of the columns I would like to select. How would I write a MSSQL query that will use the distinct ...
1
vote
2answers
35 views

RIGHT() function returning blank result

I have a single column that contains information that I need to have split up into three separate columns. I currently have a SELECT statement that works partially, but my ChangeTo column is not ...
0
votes
1answer
50 views

Filtering SQL Search Query

How can I filter results in a SQL query? Let’s say I have Products A-Z, and each product has a monthly observation for X Months, but for most products the value in the observation stays the same for ...
0
votes
0answers
17 views

postgresql how can i get list of trigger which are fired when function X is working?

my goal is to list all trigger names which are working when function X is working. i assumed it has something to do with pg_proc and pg_constraints but i couldn't figure it out.
0
votes
1answer
22 views

postgresql double count query

I have a table with 3 columns: key, status and rank. status contains numbers and rank contains t or f. key is auto numbered and irrelevant here. my goal is to count how many in each status are t and ...
1
vote
1answer
30 views

Returning case-sensitive input of case-insensitive array match

Taking a JSON table with some simple data: CREATE TABLE jsonthings(d JSONB NOT NULL); INSERT INTO jsonthings(d) VALUES('{"id":1,"email":"Test1@test.com"}'); INSERT INTO jsonthings(d) ...
0
votes
2answers
41 views

How to access row value from UPDATE sub query function?

I would need to use UPDATE like this: update offer set (bank, bank_id) = (cost, gid) from ( select cost, osm_points.gid from pgr_kdijkstraCost( 'SELECT gid as id, source, target, walk_cost as cost ...