Archive for the 'select distinct' Category

What’s wrong with my SQL Statement?

SELECT DISTINCT listing_id
FROM listings
WHERE NOT
EXISTS (
SELECT *
FROM images
WHERE images.listing_id = listings.listing_id
)
LIMIT 0 , 30
Any help would be appreciated! I’m trying to show any listing_id numbers in the ‘images’ table that are not in the ‘listings’ table. Help, I’m going nuts!
I’ve tried every combination but still get the MySQL Error 1064. I [...]

SQL: getting all unique combinations of two columns that occur?

I have a table of ordered items. Say it has ItemID, OrderID, and CustomerID. There can be multiple items per order and multiple orders per customer.
How can I SELECT every distinct combination of OrderID and CustomerID (that actually occurs in the file)?
Thanks.
SELECT DISTINCT OrderID, CustomerID FROM databasetable

How to write " in php?

<html>
<body>
<?php
echo """;
?>
</body>
</html>
while running this code getting error:
Parse error: parse error, unexpected ‘"’, expecting ‘,’ or ‘;’ in C:\wamp\www\5.php on line 4
Practically i have to use " for:
$result1 = mysql_query("SELECT DISTINCT name FROM testtable WHERE address=");
$result=$result1 & ""request.querystring("q")"";
Gotta escape the "… If you were echoing out a variable or something you’d want to use stripslash(); but [...]

I’m running a query in sql that shows how many stored procedures there r,but I just want that amountnotthelist

Basically I can get the query to work but it runs throuh all the list and the the amount is displayed at the end, but so is all the procedures. I just want the amounts displayed not all the procedures. My scipt is
SELECT DISTINCT NAME FROM USER_SOURCE;
just use "count":
SELECT COUNT(DISTINCT NAME) CNT FROM USER_SOURCE

How can i select distinct values in an LOV in Oracle Apps 11i?

Well, that’s one of the first questions i asked when i worked with value sets in oracle applications.. The answer is no way.. you cannot make a distinct select out of value set..
There is a work arround though, you can create a veiw with the required data, and then add the distinct keyword to it.. [...]

Can anyone help me with an access database problem?

I have a table of records that contains duplicate account numbers. The table is sorted so that the rows are grouped by account number. I need to select just the first row for each unique account number. Using DISTINCT doesn’t work because I need the whole row and each row is a little different except [...]

What are some significant and distinct instruments?

I have to do this one-hundred twenty project for world history for three marking periods. Each marking period, you have to provide forty examples of a topic you have selected. I chose musical instruments. PLEASE HELP! I can’t find anymore and I’m only at twenty-six for the first marking period. Please suggest ANY musical instrument [...]

i need to present both selects in one output anyone know how?

Here are the 2 selects I need to combine into one output file.
SELECT distinct a.item,
GROUP_CONCAT( DISTINCT a.size ORDER BY b.size_order SEPARATOR ‘,’ ) AS sizes
FROM sizes b
RIGHT JOIN test AS a ON a.size = b.size
LEFT JOIN test_cats AS c ON c.item = a.item
WHERE a.comment = "" AND (a.size="O/S" or a.size="Q/S" or a.size="")) as z
GROUP BY [...]

i need to present both selects in one output anyone know how?

Here are the 2 selects I need to combine into one output file.
SELECT distinct a.item,
GROUP_CONCAT( DISTINCT a.size ORDER BY b.size_order SEPARATOR ‘,’ ) AS sizes
FROM sizes b
RIGHT JOIN test AS a ON a.size = b.size
LEFT JOIN test_cats AS c ON c.item = a.item
WHERE a.comment = "" AND (a.size="O/S" or a.size="Q/S" or a.size="")) as z
GROUP BY [...]

How can I speed up this SQL Query?

I have a SQL Query that uses too many INNER JOIN statements so it runs pretty slow (takes 4 to 5 seconds to retreive 50,000 records). How can I speed this up?
SELECT DISTINCT
table_A.field_1,
table_B.field_2,
table_C.field_3,
table_D.field_4, table_D.field_5, table_D.field_6,
table_D.field_7, table_D.field_8, table_D.field_9,
table_D.field_10,
table_E.field_11
FROM ((((table_D
INNER JOIN table_A ON table_D.field_1 = table_A.field_1)
INNER JOIN table_B [...]