select a pair from an SQL table
I want to select a pair of supplier ID that meets a certain requirement, i.e. the first supplier charges more than the second one for a certain part.
SELECT DISTINCT S1.sid, S2.sid
FROM suppliers JOIN catalog ON (suppliers.sid = catalog.sid) AS S1,
suppliers JOIN catalog ON (suppliers.sid = catalog.sid) AS S2
WHERE S1.pid = S2.pid AND S1.cost > S2.cost;
Now this isn't working. Can anyone tell me where the problem is?
I have been able to create a data connection from Excel to SQL Server and execute many SQL queries successfully. But I cannot get any TSQL to work if it includes a temporary table. For example: select
Below is a code snippet for passing a table as a parameter to a query that can be used in Sql Server 2008. I'm confused though about the SELECT id.custid FROM @custids id. Why does it use id.custid
I hava very large table with 1373228 rows. I need to copy the result to excel but It does not allow me to do so. Can anyone please, suggest me that how can select the table in parts and paste it in ex
I have a mapping table tableA key value ----------- 1 John 2 George 3 Kate 4 loves 5 hates and another tableB that contains rows based on keys of tableA col1 col2 col3 ------------------ 1
Long time searcher first time poster. I am trying to create a dynamic SQL script which concatenates the dynamic part into a string to form the From clause so I can declare the table name only once (in
In table there is a column named status which can have either 1 or 2. Now I want to select pattern like this First Row 1 Second Row 2 Third Row 1 Fourth Row 2 ......
It should be simple, bit I've spent the last hour searching for the answer. This is using psycopg2 on python 2.6. I need something like this: special_id = 5 sql = select count(*) as ct, from som
I have a table with about 20 columns and 2000 rows. Example: Col1 Col2 Col3 Col4 ... A01 22 AB 11 A01 22 AX 112 A01 23 A5 11 A02 20 AB AA A04 21 AB 11 A04 21 AU 11 A04 29 AB BA A05 21 AB 11 AAA 111 X
I have two tables: A: [ date, step, status, ... ] B: [ date, step, name, ... ] I want to get result in form of [date, step, name] based on status parameter. I can easly get data from table A using f
Let's say I have a table named table1 in a sqlite3 database (via python) with two columns named 'id' and 'string' and here are the three entries in the table: id string 'a' 'google' 'b' 'apple' 'c' '
I have two tables: tblA contains a foreign key which I want to use to pull corresponding rows from tblB. The following queries will not work, but they explain what I want to do: SELECT [MyID] FROM [tb
i have to select records from two tables, but combine them in a way, here is my table loans ---- id amt date pay_period borrower_id lender_id the user table users ----- id name phone this is the sql
I'm trying to paginate using MS SQL Server 2005 in one of my ASP net applications. To fetch 10 records from the employee table I'm running the following SQL. ;WITH CTE AS ( SELECT EmployeeID, [Name],
I'm trying to select all users that their user id is not in another table. Users table (user id is user_id) Ghosts table (user id is id) this is what I got so far: $sql = select * from users where us
When i run select hex(col1) from table1; i get the result as hex number for ex: the hex(65) is 41, but i wish to get directly thro sql query the result as 0x41 instead of 41, is there a way to get the
I need to get a stratified sample of my huge table. Specifically, I want to select 1/n rows from my table without bias, i.e. select randomly, select every nth row, etc. Before I asked this question, I
I have a table like this. Name c1 c2 c3 c4 one 1 2 3 4 one 3 1 7 6 one 5 9 2 5 one 2 5 1 8 two 1 4 2 6 two etc..... i want to select a column randomly with the condition name is equal to one. the res
I'm doing a data conversion between systems and have prepared a select statement that identifies the necessary rows to pull from table1 and joins to table2 to display a pair of supporting columns. Thi
I have a table person, an associative table person_vaccination and a table vaccination. I want to get the person who has missing vaccinations but so far I only got it to work when I have the id.
I want to insert into a table an value from variable and an select result. declare @actual Date set @actual = getdate() This is my try: insert into test (ID, Date) (select ID, @actual from Table) I
I'm working on a database which has the following table: id location 1 Singapore 2 Vancouver 3 Egypt 4 Tibet 5 Crete 6 Monaco My question is, how can I produce a query from this which would result i
I am trying to perform dynamic sql select where I am selecting from a table using a parameter. SELECT null FROM @TableName However I am getting error must declare table variable @TableName. I suspect
I need to select some rows from Table 1 lets say if a value is found in Table 2. So I want to check if the value (I will enter the value from command line) is found in Table 2 and then select rows fro
I'm running SQL Server 2008 and having to load the table without computed columns in it, i.e. something like SELECT (ALL COLUMNS WITHOUT COMPUTED COLUMNS) FROM MY_TABLE Is that possible doing so? W
I am trying to pair records in a SQL table, my table looks similar to this: UID DATE TIME MateID --------------------------------------- 1 2013-06-07 08:00 NULL 2 2013-06-07 10:00 NULL 3 2013-06-07 13
I have 4 table, default_table, table_a, table_b, table_c, each have two columns, I want to select name and id from all table then sort it, it rySELECT Name,ID FROM default_table, table_a, table_b, ta
I've got a requirement to add an additional item of data to an existing row and insert the result in a second table. The data item is different for each row I am selecting, so I can't just add it to t
Delphi 2010 & Oracle Database I need to write a select statement across two tables Accounts & Master From the Accounts table, I need to select the Account_Id, Account_Number, Bank_Id, and Exte
I have a table which contains the terms of payment for a product. I want to get the latest terms for that product. In the query below it returns all the terms since my application went into production
I have notification table, which contains notification_id, type, type_id ... I want to select records which have unique type_id. I am running this query: SELECT $cols, DISTINCT type_id FROM notificati
I'm trying to write my MySQL query, but I'm stuck on this - I have multiple queries from my php to the SQL database: SET @var := SELECT MAX(first_column) FROM table; SELECT @var, table.second_column
I want to get the contents of a sql table using xml: projectID - projectName - customerID -customerName - city i want to list all columns in xml tags and nest the customer seperately inside a project
Is there any way to select, for example, first 10 rows of a table in T-SQL (working MSSQL)? I think I saw something in Oracle defined as rownum meta variable, used in a following way select * from U
I am currently transferring a large amount of records from one table to another, summarizing in the process. So, I have a SQL in this general format: INSERT INTO TargetTable (Col1, Col2, ... ColX) Tot
I'm trying to select trending #hashtags from a table and echo the hashtags in a div with MySQLi and PHP. Something that works like this: $query = mysqli_query($link, SELECT * FROM 'submissions' WHERE
I'm struggling to find an answer to a query I want to run. I want to SELECT * FROM users AND tempusers WHERE username='joe' Both tables have a column named username. I keep getting hit with SQL 1064
How do I create a sql select statement where the select column names are values in rows of another table (I am using postgresql)? I have a language table with language codes: language ======== id code
Can someone please explain how I might use Jackcess to implement the equivalent of the following SQL queries? SELECT name FROM table WHERE id = '1' SELECT name FROM table INNER JOIN table ON table.id
I have two tables that I can perfectly query seperately. table1 stores ranges: SELECT range_id, range_from, range_to FROM table1; table2 stores IDs: SELECT MAX(id) FROM table2 WHERE id BETWEEN <x&
I have some code (inherited) which selects a row from table 'members' and also some details from a row from table 'image': SELECT members.main,members.id,image.main,image.thumb,bio, altered,members.ti
Sorry if the title is unclear. Basically I'm trying to select certain records from multiple tables then update a certain column value for the returned records. T-SQL Implementation UPDATE CUSTOMERS S
Having this table Table Items itemID itemTitle itemContent and this Table MyList userID itemID deleted how can I select all rows from table Items and showing the field deleted, even if the i
I spent a lot of time building this select, but Im not able to solve it. I have 2 tables. First table is called car and has PK (primary key) id_car and another columns name and so on. Second table is
I'm trying to retrieve a unique set of category/sub-category relationships from a table and I want to make sure I'm doing it right so I am getting all the data. For example I want the below.. Animals
In my application I want to select all data from table1 and the maximum id of the related table2. The problem is, that the SQL works fine if there is a entity in table2. But if not the restulset is fi
How to select rows from a table while ignoring the duplicate field values? Here is an example: id user_id message 1 Adam Adam is here. 2 Peter Hi there this is Peter. 3 Peter I am getting sick.
I am going to do my best to clearly describe what I am trying to do. I am using a DBISAM SQL database. We sell t-shirts, and lots of different kinds. I am trying to update our product database with va
I have table created by ORM named 'key'. 'key' is MySQL keyword so I cannot select it just SELECT * FROM key;. How to perform select from table named 'key' in MySQL?
This is little confusing me how to select dates from table on continuous basis. Suppose i have absent_report table and have entries like this, Sno Code date 1 101 01-01-2014 2 101 02-01-2014 3 101 03-
I've got a SQL Server table with about 50,000 rows in it. I want to select about 5,000 of those rows at random. I've thought of a complicated way, creating a temp table with a random number column,