Union SQL for multiple tables

I want to show the results of both tables on the same querys, the tables are identical but one stores historic information and the other one has today's info (online), my tables look something like this. Historic Table: TBL1 T_ID Resolve Date -------

ORACLE searches the number based on two columns

I have an Oracle database Table where I have many columns in this particular table, but i want to get result on basis of computation between two columns as described below Project|Status -------|-------- 1 | Done 1 | Pending 2 | Done I want to get co

Is there a way to write async sql requests in sql server

I'm working on a sproc that needs to run several independent select statements. So let's say I have 3 select statements like this: select * from x into #x select * from y into #y select * from z into #z Let's say each select statement takes 2s to com

How to find all records that cause a loop

I am writing a query that assign level code to each item in the while loop. I have the table that have data problem need to be clean up. some of the records in the table looks like following: Product Ingredient XX YY YY XX YY ZZ ZZ XX How should I us

SQL joined result table as alias

Is there a way to give a result table of a join an alias? Example query: SELECT * FROM t1 JOIN t2 ON t1.num = t2.num AS result; Yes! select result.* from (SELECT * FROM t1 JOIN t2 ON t1.num = t2.num) result You do need to watch where you've got colum

Mysql very slow subquery optimization

I am building a sql query with a large set of data but query is too slow I've got 3 tables; movies, movie_categories, skipped_movies The movies table is normalized and I am trying to query a movie based on a category while excluding ids from skipped_

SqlException: Incorrect syntax near '='

I'm taking some basic lessons and I'm trying the simplest example possible but I'm getting a SQL exception during the reader execution. An unhandled exception of type 'System.Data.SqlClient.SqlException ... Incorrect syntax near '='. Here's the core

How to link params with raw query mysql yii

i am using raw text query to generate results. But in order to avoid sql injection it want to parameterize query on both the variable i.e $from & $to, passed in userStat() function. puclic function userStat($from, $to){ $sql = "select u.user_id a

Create a relationship in phpMyAdmin

Being new to phpMyAdmin, I want to create a relation between a column (column_1) of one of my tables (Table_1) with a column (column_2) in another table (Table_2). I first index column_1 in Table_1 and when I want to create the relation in relation v

Count the number of times a record appears

I have a query which has a column, schloc schloc TEST TEST TEST TEST NOTEST NOTEST NOTEST NOTEST RANDOM RANDOM RANDOM RANDOM I want to put it in a table in my SSRS report like this: TEST NOTEST RANDOM 4 4 4 How can I use the COUNT for my expression t

where the declaration does not work properly in c #

I am using MYSQL in my c# app. There are some string values in mysql table and there is a textbox that client can write in that and then I use this statement to show the results: "SELECT ID,METER FROM DB.TABLE1 WHERE METER >= '" +TEXT1.text.t

Linq lambda expression number to several tables select

I have three tables, which two of them are in many to many relationship. Picture: This is the data in middle mm table: Edit: Got until here, I get proper 4 rows back, but they are all the same result(I know I need 4 rows back, but there are different

Grouping SQL elements with XSL

I've been working on a XSL style sheet for a specific SQL query table. I would like to group the results by 'tcode' and sum the values of each of the number columns. Any help would be appreciated. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/

SQL query for .005

I want to be able to do a SQL Query that gets all numbers that end in .005 Select * from amount where (numbers end in X.XX5) I don't care what the numbers are for XI am assuming you don't care what the first and second digit after the decimal is.Try

Create stored procedures with PDO in PHP

I am reading a TEXT file from PHP and trying to execute commands from it, like creating a DB and all the tables and procedures it has. My code creates the tables but does not create Stored Procedures given in the file. DELIMITER $$ DROP PROCEDURE IF

ORDER BY & ldquo; ENUM field & rdquo; in MYSQL

There is a field 'noticeBy' enum('email','mobile','all','auto','nothing') NOT NULL DEFAULT 'auto'. As it known ordering by ENUM field performs relative to its index. However, how it possible make order by its values?As documented under Sorting: ENUM

Database design for tournament management software

I'm currently designing a web application using php, javascript, and MySQL. I'm considering two options for the databases. Having a master table for all the tournaments, with basic information stored there along with a tournament id. Then I would cre

Find if two dates are more than 6 months apart with Oracle

so for my university coursework, i have to create an oracle database for an airline. (this is my first time working with oracle) part of my requirement is to identify whether pilots are fit to fly. to do this, my employee and pilot_test tables are se

Do indexes work with the group function in Oracle?

I am running following query. SELECT Table_1.Field_1, Table_1.Field_2, SUM(Table_1.Field_5) BALANCE_AMOUNT FROM Table_1, Table_2 WHERE Table_1.Field_3 NOT IN (1, 3) AND Table_2.Field_2 <> 2 AND Table_2.Field_3 = 'Y' AND Table_1.Field_1 = Table_2.Fie

Calling 2 different databases

I'm trying to have the PAYPAL IPN work with 2 different sites, I can't get the php script to know which database to work with. Here's my script. // read the post from PayPal system and add 'cmd' $req = 'cmd=_notify-validate'; foreach ($_POST as $key

What inefficiency are the JOIN of the virtual table?

Say I have a query like this, where I join a number of virtual tables: SELECT table1.a, tbl2.a, tbl3.b, tbl4.c, tbl5.a, tbl6.a FROM table1 JOIN (SELECT x, a, b, c FROM table2 WHERE foo='bar') tbl2 ON table1.x = tbl2.x JOIN (SELECT x, a, b, c FROM tab

The Mysql COUNT result rows for an associated table

I have users ------------------------ id | name | other_stuff..... . engagement ------------------------ user_id | type_code | type_code is a varchar, but either A, B, C or NULL [ EDIT for clarity: Users can have many engagements of each type code. S

How can I iterate through all the nodes in XML - Sql2008

How can I iterate through all nodes in XML document using T-SQL (SQL2008). I need to create table schemas for each distinct Node Path (elements) in the document. declare @x xml=' <logins> <roles> <role name="Administrator" /> &

Why do you need to GROUP by columns in a CASE statement?

I'm trying to run a query in SQL Server 2008 against a table where some of the data was entered inconsistently and I have to handle this. Table data example: OrderID Qty Price MarkedUpTotal 1 10 1.00 11.00 1 -1 1.00 -1.10 1 -1 1.00 1.10 I have to han