|
-
Aug 20th, 2013, 09:08 AM
#1
Thread Starter
Fanatic Member
Why does this SELECT DISTINCT querie not work?
Hi Guys,
For some reason this isnt working and wont display any results...
Any ideas?
<?
$query1 = mysql_query ( "SELECT DISTINCT `artist` FROM `Artists` WHERE `Genre1` = '$usr->Genre1' OR `Genre2` = '$usr->Genre1' OR `Genre3` = '$usr->Genre1' OR `Genre1` = '$usr->Genre2' OR `Genre2` = '$usr->Genre2' OR `Genre3` = '$usr->Genre2' OR `Genre1` = '$usr->Genre3' OR `Genre2` = '$usr->Genre3' OR `Genre3` = '$usr->Genre3' ORDER BY RAND() LIMIT 0,1" );
while ( $art = mysql_fetch_object ( $query1 ) )
{
?>
Basically, I need it to select an artist and it will display the artist picture, but at the moment it sometimes shows the same artist more than once.
Regards,
Jamie
-
Aug 24th, 2013, 06:15 AM
#2
Thread Starter
Fanatic Member
Re: Why does this SELECT DISTINCT querie not work?
-
Aug 24th, 2013, 07:36 PM
#3
Re: Why does this SELECT DISTINCT querie not work?
When you need a distinct object that when you use "where" if you just want to find everything you use
php Code:
$query1 = mysql_query ( "SELECT`*` FROM `Artists`
for distinct select use
php Code:
$query1 = mysql_query ( "SELECT `artist` FROM `Artists` WHERE `Genre1` = '$usr->Genre1' OR `Genre2` = '$usr->Genre1' OR `Genre3` = '$usr->Genre1' OR `Genre1` = '$usr->Genre2' OR `Genre2` = '$usr->Genre2' OR `Genre3` = '$usr->Genre2' OR `Genre1` = '$usr->Genre3' OR `Genre2` = '$usr->Genre3' OR `Gen
That is remove the "DISTINCT" from the select statement.
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Aug 26th, 2013, 02:49 AM
#4
Re: Why does this SELECT DISTINCT querie not work?
Wouldn't your sql just return 1 record everytime by its "LIMIT 0,1"?
@Nightwalker83: How would that return a DISTINCT record?
-
Aug 26th, 2013, 03:23 AM
#5
Re: Why does this SELECT DISTINCT querie not work?
 Originally Posted by dee-u
How would that return a DISTINCT record?
Isn't a distinct value just a matter of using "Where" in the search?
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Aug 26th, 2013, 03:33 AM
#6
Re: Why does this SELECT DISTINCT querie not work?
No, distinct would return unique records. There could be 2 or more records returned by a query that satisfies a WHERE clause and using DISTINCT would eliminate the duplicate records. We could also just use GROUP BY which is the same as using DISTINCT.
-
Aug 26th, 2013, 03:47 AM
#7
Re: Why does this SELECT DISTINCT querie not work?
 Originally Posted by dee-u
No, distinct would return unique records. There could be 2 or more records returned by a query that satisfies a WHERE clause and using DISTINCT would eliminate the duplicate records. We could also just use GROUP BY which is the same as using DISTINCT.
Ah ok! I just looked at a Java example of mine dealing with coloured pencils and it uses.
java Code:
"SELECT colour, size "+ "FROM tblPencils " + "WHERE colour = ? "+ "ORDER BY colour";
by as you say that example is using "ORDER BY".
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|