My problem is solved but now i have a few performance questions. I want an overview of my caught pokemon for all editions, it works as far as i tried, but i don't think it's best practice. select #p.idpokemons as ID, as Pokemon, as Tr

Results of sorting and limiting SQL joins

I have the following two tables (populated with more data): rating ID | user_id | rating_value | date 1 1 0.6 2016-04-02 2 2 0.75 2016-04-05 3 1 0.4 2016-04-08 4 2 0.5 2016-04-12 recommendation ID | user_id | recommendation_text | date 1 1 'a' 2016-0

Select different channels in the same row

I have a table called "character_certifications" where I need to select different strings as count in the same result. The table looks like this: classId charId var 0 268482320 EmergentAbility65-1 0 268482320 EmergentAbility65-2 0 268482320 Emer

Using the command between SQL

I have the following table drink_name........cost........calories Black.............1...........30 Clue..............2...........40 Elephant----------3...........50 When I use the between command for characters (it excludes ending positions) select d

How to use escape with LIKE in SQL Query

My Query is : declare @param1 INT, @param2 nvarchar(max) set @param1 = 1 set @param2 = '[Test_data_forQry],[Next_Test_Data]' SELECT * FROM Table1 WHERE ColumnA = @param1 AND (',' + @param2 +',' LIKE '%,' + CONVERT(VARCHAR, ColumnB) + ',%'); The squar

Concat with NULL

I have a query which looks something like this: select distinct col1, ( select ltrim(str(col2))+',' from @temp t2 where t2.col1 = t1.col1 for xml path('') ) col2 from @temp t1 Some of the values in col2 are null, so instead of displaying a string wit

Select the instruction in the decode function

so I am writing a select query using a decode function, and set the result into a variable. The thing is, when there is no lines, I always got no result error. I tried decode with the value, and counting, but no results. SELECT decode(count(id), 0, (

Where is Oracle sqlplus?

Background Coming from a mysql background, I find getting started with Oracle quite a different experience. Question Where do I find this command tool for Oracle? I have checked wikipedia and it only says: An Oracle programmer in the appropriately co

Oracle SQL, using a sequence in a separate select query

I am trying to insert some data into a table from a select statement. I know I can do it like this: insert into new_logs (idLog, logEntry) (select idLog, logEntry from old_logs) But, I am running into a problem when trying to execute this type of que

Results of the SQL query to the file script

I am running SQL express on a windows 2008 R2 server and trying to write a script to periodically query a database and save the results to a file. I have used: sqlcmd -Q SELECT DISTINCT Date from MMD_Scale ORDER BY Date ASC -o testresults.txt and bcp

How to divide a file into batches by using PowerShell

How do I split file on batches using powershell? I have a sql post deploy file with multiple batches. Below is example of my postDeployment.sql file. IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'StoredProc') AND type in (N'P', N

MySQL query: selection of the latest results

I have a MySQL table with data, and would like to select the most recent entry for a specific test that was conducted. table: research columns: id (int), projectid (int), test (varchar), when (datetime), result (longtext) Example of rows: 1, 6, "Test

Link multiple tables in a database

I have actually this little function working as supposed: Function createAttached(strTable As String, strPath As String, strBaseTable As String) As Boolean On Error GoTo CreateAttachedError Dim tdf As TableDef Dim strConnect As String Dim fRetval As

How to combine these SQL queries to display an output?

Help needed to combine the output of this query together.How it can be done??TQ select facility, route, operation, script_id from F_ROUTEOPER where facility = 'A01' and operation in ('6910','7976') AND src_erase_date is null and (script_id not in ('P

Run a subquery in MySQL that returns multiple rows?

I am executing a query that obviously contains a subquery in MySQL. Let me just jump into the code: SELECT DATEDIFF(CURDATE(), (SELECT due FROM checkOut JOIN People ON checkOut.p_id = People.p_id WHERE CASE WHEN DATE_SUB(date_add(CURDATE(),INTERVAL 4

Optimization of the MySQL query LEFT JOIN

My goal is to select articles where the primary_category_id (articles table) or any of the secondary categories (articles_secondary_categories join table) are a given value. In this example query, category 1. I tried using other types of joins but th

Adding multiple tables to the MySQL database using PhpMyAdmin

I have created a form and from the form fields I have created a sql file that I am going to use to create all the database fields for the form in my mysql database. I am using type following code to create the entries with : ALTER TABLE `rok5g_chrono

Attach tables by appropriate period

In a postgresql database I have 2 tables like these ones: Table items: item_id item save_date (date dd/mm/yy) ---------------------------------------------- 1 car 01/12/11 2 wheel 10/12/11 3 screen 11/12/11 4 table 15/12/11 Table periods: period_id p

Is it possible to generate a SQL update script for a data line?

I have a single row of data in a SQL Server table that I'm going to update for testing purposes. Before I update it, I'd like to save the existing values into a .SQL file so that I can undo my changes once I verify my code is working properly (rollba

Using ORDER BY on indexed columns

In SQL Server 2008, let's say I have an index (LastName, FirstName) on the table Employees. The index is sorted ASC on both columns. Is there any point to the ORDER BY in the following query? SELECT LastName, FirstName FROM Employees ORDER BY LastNam

Is it possible to set ExecuteUpdate to respect session filters?

The query below makes use of ExecuteUpdate. I want said method to respect session filters. Is this possible? //This line seems to make no effect. _session.EnableFilter(FilterName).SetParameter(FilterParam, Value); _session.CreateQuery(String.Format("

Reverse in Oracle this path z / y / x to x / y / z

How would I do in a SELECT query to reverse this path : z/y/x for x/y/z where / is the delimiter and where there can be many delimiters in a single line ex: select (... z/y/x/w/v/u ...) reversed_path from ... The simplest way would probably be to wri