Select the first unique value in the table

I am looking for SQL how to select first unique value in table for column OBJID. What I would like to have is result, where just first existence of OBJID (group by) or (distinct) didn't work. As well I have searched everywhere, but couldn't find work

Special use of candidate keys, minimal nature

I know that, "A candidate key is a minimal subset of a superkey" That means there cannot be any other super keys inside a Candidate key. What i don't understand is that, Where can we use this special property of a candidate key in a database des

PHP / MYSQL counting commands

Orders table: Order_items table: Users table: $sql[2] = "SELECT, COUNT(o.user_id) AS order_count, (oi.quantity * p.price) AS total_price FROM users AS u INNER JOIN orders AS o ON = o.user_id INNER JOIN order_items AS oi ON oi.order_id = o

returns a value if null or null. tsql

I have recently written a report using a variation of this SQL Statement: select project.*, TF.*, TW.*, TR.*, TH.* from (select sum(Quantity) as FQty from unitType where Type = 'F' group by type) TF, (select sum(Quantity) as WQty from unitType where

SQL - The most common value in the attached table column

I have three tables described below: Area (Id, Description) City(Id, Name) Problem(Id, City, Area, Definition): City references City (Id), Area references Area (Id) I want to find the most frequent value of Area(Description) that appears in Problem f

tsql - extract only part of a dynamic string

I have a table with a column that holds a string such as: xx-xx-xxx-84 xx-25-xxx-xx xx-xx-123-xx I want to go ahead and query out the numbers only, but as you can see, the numbers are placed at different places in the string every time. Is there away

using an eloquent model property in subquery with function

My question may be confuse because I've started learning Laravel. Can I use eloquent model property in subquery of with() function? I have classes, students, and grades tables. I wish to get $classes = [{id:1, name:'maths', students:[{id:2, name: joh

How to Reply to Front-End Search in SQL Server Query

I have an application. Functionality required is: There is 1 dropdown and a gridview underneath. When the page is loaded for first time, nothing is selected in dropdown. The query works like: Select * from myTable; Then when we select somethi

I can not create a simple table

I try to Write the SQL code to create the table named 'EMP_1'. This table is a subset of the EMPLOYEE table, and the structure of the table is summarized as shown below. This is the information: Attribute Name Data Type Remarks EMP_NUM CHAR(3) PK EMP

query oracle to group the difference of date by hour

I am hoping to get some help to write some SQL that I have had no success writing myself. I have a table with the data: ID StartDate EndDate 1 01/01/2000 04:30 AM 01/02/2000 06:15 AM 2 01/03/2000 06:10 AM 01/03/2000 07:00 AM I need to get the followi

SQL and oop in goal-c

This is probably a stupid question, I tried looking for similar post but I couldn't find any so if there's some. I'm starting to use SQL, it's quite easy but how can I save an entire object in it? I try to explain better. If I want to save an instanc

Delete the SQL output when the value is NULL

The below SQL query is working for me, but it returns the property value when there staffNo is null 6 times(Once for each staff member). I want to return the property owner even if the staffNo is null, without 6 returns. SELECT s.branchNo, s.staffNo,

SQL - Create a view from multiple tables

I have three tables: POP(country, year, pop) FOOD(country, year, food) INCOME(country, year, income) I am trying to create a view such as: V(country, year, pop, food, income) This is my code so far. I don't think its correct: CREATE VIEW V AS (SELECT

Selection of the 2nd line in sql

I want to select the second row only from the table. From the ClientUserName column. SELECT ClientUserName, DestHost, count(DestHost) counts FROM #ProxyLog_record WHERE ClientUserName = (Select top 1 ClientUserName from #ProxyLog_count_2) GROUP BY Cl

SQLite JOIN two tables with duplicate keys

I need to join two tables on two different fields. I have table 1 like this: key productid customer 1 100 jhon 2 109 paul 3 100 john And table 2 has same fields but aditional data I must relate to first table key productid customer status date ... 1

ORDER BY varchar with [a-9] instead of [0-Z] in SQL

By default, SQL orders numbers before characters. So if I have the column "name": abc ab1 a1b 1ba 1bac b21 Since SQL sorts by 0-Z (first 0 to 9, then a-Z), the query SELECT * FROM ... ORDER BY name will result in: 1ba 1bac a1b ab1 abc abc1 b21 B

Example of real life, when to use OUTER / CROSS APPLY in SQL

I have been looking at CROSS / OUTER APPLY with a colleague and we're struggling to find real life examples of where to use them. I've spent quite a lot of time looking at When should I use Cross Apply over Inner Join? and googling but the main (only

SQL grouping and sum

I would like to know how to get the following result set out of my current result set. My query is like this: SELECT SUBSTRING(Col1, 1, 3) As 'Series', b.Col2, cast(c.Price * c.Qty as money) AS Total from tableName a inner join .... ... WHERE date be

SQL statement order by maximum input

I have a table called "reports" it looks like: user_id | report_post 1 2 2 2 3 2 4 10 Now I want to list the first three entries at first, cause the reported post id "2" is 3 times in this table... i want so sort them by the maximum of

create a random block in jdbc and write it to oracle

I want to create many blobs in java [in memory] and write it to Oracle table. What I want is the blob[bits inside it] to be random or sudo random so that oracle would not be able to do a lot of pre-optimization while storing the blob to the table. So

Error converting data type nvarchar to date

I have an SQL Function that takes a String, a DATE and another string. EXEC dbo.ReplaceString 'You ve been subscribed to the ##company## newsletter.', NOW,'BIG DEES' CREATE Function [dbo].[ReplaceString] ( @main_message As Varchar(500), @date_sent As

Sharing rules between javascript and SQL

I'm mostly looking for ideas here. The odds of my group purchasing something to solve the problem is incredibly low, but go ahead and suggest any commercial products that would help. The basic problem stems from the following scenario: Users input da

Synchronizing client-server databases

I'm looking for some general strategies for synchronizing data on a central server with client applications that are not always online. In my particular case, I have an android phone application with an sqlite database and a PHP web application with

A correct way to get the date between dates in SQL Server

I have a table in SQL server which has a DATETIME field called Date_Printed. I am trying to get all records in the table which lie between a specified date range. Currently I am using the following SQL DECLARE @StartDate DATETIME DECLARE @EndDate DAT