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)

0
votes
0answers
2 views

Entity ID field that can refer to multiple tables?

In designing both audit tables and notification tables, I've run into an issue where I need a row to refer to an entity in another table, but which table that entity is isn't always the same. For ...
0
votes
1answer
17 views

Selecting where nullable boolean is not true

I have made the following code for select a record that isn,t true. SELECT * FROM Table WHERE Bool != 'true' OR Bool IS NULL; Why is the check Bool != 'true' not enough for a nullable boolean?
1
vote
2answers
40 views

How can I Insert when not in table and when max timestamp T-SQL

I am trying to insert rows from one table to another that are not in the one I am moving them to. I also want to only move the ones that have the highest datestamp. (I want to only insert rows that ...
0
votes
0answers
13 views

Select custom meta_key and meta_value from wordpress in single query [migrated]

I have a custom field named 'video_code' and yoast seo's custom field named '_yoast_wpseo_title', both under meta_key column like this: meta_id | post_id | meta_key | meta_value 123 ...
3
votes
4answers
107 views

pgsql select distinct on multiple columns

Supposing we have four columns (a,b,c,d) of the same data type, Is it possible to select all distinct values within the data in the columns and return them as a single column or do I have to create a ...
0
votes
1answer
30 views

how to use a specific column for a day

CREATE TABLE `csptargets` ( `id` int(11) NOT NULL AUTO_INCREMENT, `start_date` datetime NOT NULL, `end_date` datetime NOT NULL, `cspcode` varchar(11) NOT NULL, `vol`decimal(20,3) NOT NULL ...
1
vote
1answer
40 views

Optimizing a query that performs worse on a smaller dataset

I am trying to run this query. The * is just for simplification, I'm selecting ~10 specific fields for some calculations. SELECT * FROM `orders` LEFT JOIN `orders_processed` ON ...
-1
votes
0answers
8 views

Filter several columns and order it from a table

I am looking to filter it for values 1 and 2 (door open/shut)… and ensure it is sorted in DATE and TIME order…. and finally by bus stop id. From that picture ... Anybody can help me with it? Thank ...
0
votes
0answers
17 views

Why is there a difference in CSV Export Results of Oracle SQL Developer and SQL Plus Spool

When I export data from SQL Developer GUI, setting format: csv, left enclosure: ", right enclosure: ", and Encoding: UTF8, I get data exactly the way that I need it for processing in Python. ...
0
votes
1answer
30 views

Script works but Im not sure this is the best format

I have a survey table which contains mostly integer. I want to make it readable for end user so I use select statement as below: SELECT CASE s.Country WHEN 1 THEN 'One' WHEN 2 THEN 'Two' ...
0
votes
2answers
72 views

Using Like with variables?

I have an odd situation where I have a column called (TransmittalNumber) with datatype of VarChar (75) in a table named (Transmittal Sheet). I want to query this table to find the transmittal numbers ...
0
votes
0answers
9 views

When to use tags vs binary fields in a constituent management system?

I have a table of Constituents and I want to track yes or no qualities like: are they a teacher? are they an elected official? are they philanthropists? There will be less than a dozen of these ...
1
vote
2answers
20 views

Troubleshooting high disk read - buffer cache query

I have a table tbl_Table1 that is about 5 GB in size and has millions of rows. It has these columns: ID, ContractID, Person, Address1, Address2, and many more. One clustered index on the PK, ID. I ...
0
votes
1answer
22 views

Is it possible to select distinct values in a json document using PostgreSQL?

I have a column that is using the JSON type. I would like to perform a query to select all distinct records for a particular field in the JSON string: I.e. given these three documents { id: 1, s: ...
0
votes
1answer
29 views

mysql Quiz leaderboard filter by points, time taken

I have a quiz report table which shows a report for every quiz a user takes. I need to create a leaderboard from this, which shows the top users best score, filtering by points and then time taken. ...
-3
votes
0answers
13 views

How to convert the rows to column in View from old design to New design [on hold]

How to convert the table structure in view from old design to New design .
3
votes
2answers
479 views

Is there a way to calculate yesterday / today of last month / year in SQL?

Is there a way to calculate today (and yesterday) of last month (and last year) in SQL? Assuming today is 26-May-2015 then how to find? Today of last year i.e. 26-May-2014? Today of last month i.e. ...
-3
votes
0answers
31 views

What are some good puzzles to test my Advanced T-SQL skills? [on hold]

What are some good puzzles to test my Advanced T-SQL skills ?
5
votes
1answer
56 views

Warning for missing statistics in execution plan

I have a situation that I cant understand. My SQL SERVER execution plan tells me that I have missing statistics on the table, but the statistics is already created. Please see the screens. But if ...
8
votes
1answer
408 views

Why is SELECT * much faster than selecting all columns (in a different column order) by name?

On a table with columns a,b,c,d,e,f,g,h,i,j,k I get: select * from misty order by a limit 25; Time: 302.068 ms And: select c,b,j,k,a,d,i,g,f,e,h from misty order by a limit 25; Time: 1258.451 ms ...
3
votes
1answer
70 views

How to check foreign keys related to a table

How to see foreign keys related to a table in MySql? Background : I wanted to drop a table in MySql which has a foreign key constraint. When I do it I get this: Error Code: 1217. Cannot delete or ...
3
votes
1answer
58 views

How is encoding done in SQL database tables for pattern matching?

Are strings in table columns represented as bit patterns or Unicode? Does the database engine bring them into memory in a different representation character set from the disk-persisted ...
0
votes
0answers
19 views

For any SQL query, do there exists a unique translation into relation algebra

I have been studying databases and I understand that for each query that a database user type, the DBMS translate them into relational algebra operations before applying them to the database. My worry ...
2
votes
1answer
40 views

Query to flatten schema

I have the following tables and columns: Users id | other-non-important-columns Containers id | Users_id | other-non-important-columns Content id | Container_id | other-non-important-columns ...
1
vote
1answer
44 views

Find all tables that are related to a view recursively sql server

I have a view-A that is comprised of other views (View-B View-C) and I would like to list all the tables that used by View-A (which would include the tables used in View-B and View-C). When I use ...
0
votes
0answers
26 views

Need some help building a query to get info from several tables

I have this semi-complex table structure: And I need to return this data: { "id": "10111001", "rep_id": "30000001", "targets_id": "60011001", "brands_id": "10010001", "brand_name": ...
1
vote
1answer
26 views

How to get row count from all tables of a schema ( without using information schema )

The query should collect data from table name , schema name from information.schema and row count should be taken from actual table.
0
votes
1answer
49 views

Arithmetic operations on a table

can anyone give me some advice on the following situation: I have two basic tables: Then a view created by the two: select product.IDPRODUCT, sum(quantity) as totalOut, PRODUCTSTORAGE.DATAINPUT, ...
2
votes
3answers
68 views

SQL actually executed as planned in ORACLE?

I wonder if SQL is definitely executed as execution plan. I mean.. is the actual SQL execution process always consistent with execution plan, i.e. does the same SQL always give the same plan?
2
votes
1answer
25 views

Dividing values from a single column into 2 based on a rule

I am trying to create an SQL query to divide into 2 separate columns based on a rule. My table is as follows Name | Item ID | Parent ID ----- | -------- | ---------- A | 1 | Null B ...
0
votes
1answer
23 views

How to insert UNIQUE IDs values from several tables into events table

I have a table called events defined as follow: rep_id, hcp_id, brand_id, email_id and content_id is the IDs in other tables. event_type should be kind of array containing this values: [ ...
0
votes
1answer
15 views

Function for generate a huge and possible random relationship between tables

I have this two tables and N:M relationship between them: Let's said I am managed to create a lot of media and emails records but I need to create the relationship between them. I can do this ...
1
vote
1answer
113 views

Selecting rows from same name table from multiple databases in single result set

For some reason, I have a table Table_1 in n databases (same name and schema structure) instead of one single databases. The columns are like this: | Column_1 | Column_2 | I can select data from ...
1
vote
0answers
29 views

SQL 2008 R2 Agent stopping sp_who2 running and can't view database or Agent properties

We're experiencing an unusual issue with SQL 2008 R2 SP2 (10.50.4297) where the SQL Agent had stopped but would not restart (this has been fine for months). After investigating the issue we had to ...
0
votes
2answers
29 views

Insert data into table where 4 fields are the same and the fifth changes

I have a table with this structure: username varchar(35) startdate datetime enddate datetime saledate datetime packageid int for each username there are 5 packages, so one username has 5 records ...
1
vote
1answer
86 views

Slow Performance caused by Correlated Sub-queries & Clustered Index Seek

I'm running a query in which one of the tables (FIELDDATA) has nearly 400,000 records which is taking more than 2 minutes to execute. I ran the execution plan, and noticed that the clustered seek ...
-1
votes
0answers
23 views

need to but the date for the sql how can i do that can anyone help me with it please [closed]

This is the code I did the coding correct but I need to put the date in the coding could anyone help me with this please where do i put the dateFROM and DateTo in the coding below SELECT ...
0
votes
0answers
29 views

Retreive data EXEC SQL for temp table? [closed]

Is it possible to retrieve the data from usage of EXEC SQL and paste the data inside of a temp table? If yes, can you possible show me? I have a sample of data in this link ...
0
votes
1answer
34 views

Usage of ExecSQL in UDF?

Problem: is it possible to use sp_executesql or EXEC inside of a user defined function? Thanks!
0
votes
0answers
16 views

How to connect to a |Database from SQL Script, in SQL developer

Hi i am trying to connect to a DB using a connection string mentioned in a Script file.. in SQL developer. I am using the below format Connect USERNAME/PASSWORD@HOSTNAME:PORT/Service_name.. But its ...
0
votes
1answer
27 views

Passing filter params to a sub query

I'd like to create a view from the query below, but the query contains a sub query which I need to apply a filter to (the place is marked with a comment). I'm wondering if it's possible somehow to ...
1
vote
1answer
43 views

Generate rows based on value in 2 columns. Bug?

I have the following table in Oracle: ID START END _ID01 AB050 AB100 _ID01 AB101 AB150 _ID02 AB0251 AB0300 _ID01 AB00301 AB00302 I want to generate as many rows and every ...
1
vote
2answers
57 views

How to pull number code from strings buried in parentheses?

I have string data (ProductDescription) that includes product names and ID numbers and need to pull the ID numbers for cross-referencing... Data Samples: Widget (1234) Different Widget (123) Many ...
0
votes
1answer
14 views

How do I get the some of the values from 2 foreign keys in a table?

I've spent a good amount of time on this but, still have no idea as to the sql query I can use to get the student name, and class name from the payments_per_student table. edit: This using JPA work ...
1
vote
1answer
26 views

Optimize view (and underlying table) for averaging timestamps into hours

I have this table: CREATE TABLE spp.rtprices ( "interval" timestamp without time zone NOT NULL, rtlmp numeric(12,6), rtmcc numeric(12,6), rtmcl numeric(12,6), node_id integer NOT NULL, ...
1
vote
3answers
46 views

SQL self join with condition

I have table like: bu_id bu_name parent_id 1 DefaultBU NULL 601 bu1 1 602 bu2 601 603 bu3 NULL 604 bu4 603 I want to retrieve the ...
-2
votes
1answer
36 views

Usage of COALESCE? [closed]

Today: table abc a b c d ---- ---- ---- ---- 1 null 2 3 null null null 7 null 5 null 4 1 = e 7 = b 5 = f 3 = i 2 = w 4 = o The Goal is to retrieve this ...
0
votes
1answer
31 views

Options for structuring multiple associations to a record

This is 101 level stuff and I promise to read a book later, but in the meantime, given the following three tables: Product --------- ProductId (uniqueidentifier) User --------- UserId ...
7
votes
1answer
849 views

Why 0 is equal to empty string?

I need some help in finding why the following T-SQL statement returns 1 (true): SELECT IIF( 0 = '', 1, 0) I guess someone has change an ANSI option like SET ANSI_NULLS or something else that is ...
-1
votes
0answers
26 views

SQL Broadband Market Dilemma [closed]

edit -- Hi I see this post has been closed. Not sure what that means, but I'm guessing I wont be getting an answer. Any idea on where I can go on the internet to get an answer. I've been on-line for ...