hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : MySQL query problem
Reply

Forum Jump

MySQL query problem

Reply Post New Thread In Programming Discussion Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old
New Member
 
Join Date: Jan 2007
Posts: 3

MySQL query problem


Any obvious reason this query does not work as expected? it returns the correct records - but ignores the Order By request:

Code:
select distinct sql_calc_found_rows b.*, u.username from sc_users as u, sc_bookmarks as b 
where b.uid = u.uid and ((b.bstatus = 0) or (b.uid = 1)) and b.uid = 1 ORDER BY b.bDatetime desc
This similar one does work correctly:

Code:
select distinct sql_calc_found_rows b.*, u.username from sc_users as u, sc_tags AS T0, sc_bookmarks as b 
where b.uid = u.uid and ((b.bstatus = 0) or (b.uid = 1)) and b.uid = 1 AND T0.bid = b.bid ORDER BY b.bDatetime asc



Sponsored Links
  #2  
Old
Web Hosting Master
 
Join Date: Mar 2006
Posts: 961
Quote:
select distinct sql_calc_found_rows b.*, u.username from sc_users as u, sc_bookmarks as b
where b.uid = u.uid and ((b.bstatus = 0) or (b.uid = 1)) and b.uid = 1 ORDER BY b.bDatetime desc
for:

Code:
SELECT DISTINCT sql_calc_found_rows b.*, u.username
FROM sc_bookmarks b
LEFT JOIN sc_users u ON (u.uid = b.uid)
WHERE ((b.bstatus = 0) OR (b.uid = 1)) AND b.uid = 1
ORDER BY b.bDatetime DESC

  #3  
Old
New Member
 
Join Date: Jan 2007
Posts: 3
Not quite?

I am not much of a SQL expert - do not have the hang of this obviously - as this is throwing an error:

Code:
SELECT DISTINCT sql_calc_found_rows b*, u.username
FROM sc_bookmarks b
LEFT JOIN sc_users u ON (u.uid = b.uid)
WHERE ((b.bstatus = 0) OR (b.uid = 1)) AND b.uid = 1
ORDER BY b.bDatetime DESC
Code:
#1064 - You have an error in your SQL syntax; check the manual that 
corresponds to your MySQL server version for the right syntax to use near 
' u . username  FROM sc_bookmarks b  LEFT JOIN sc_users u ON ( u . uid = b . uid ' at line 1

Sponsored Links
  #4  
Old
Web Hosting Master
 
Join Date: Mar 2006
Posts: 961
In my posted version, there was a dot in it:

Code:
b.*, u.username

  #5  
Old
New Member
 
Join Date: Jan 2007
Posts: 3
Well - absolutely right.

I lost the "." somewhere - but when I was studying the code - it was in the forum - with the "." so I did not catch it.

Gracias. Now - I just have to translate it back into the PHP to get it working.

Reply

Related posts from TheWhir.com
Title Type Date Posted
Tesora's OpenStack DBaaS Supports MongoDB, Cassandra, Redis, and MySQL Web Hosting News 2014-05-23 14:53:11
Google Releases Hosted Database Service Cloud SQL to General Availability Web Hosting News 2014-02-12 13:46:02
Google Cloud Provides Support For Native MySQL Connections Web Hosting News 2013-11-01 14:36:06
PHP And MySQL Scaling: Preparing A Startup For Growth Blog 2014-04-24 13:27:35
Alert Logic Releases New Version of Security and Compliance Solution Web Hosting News 2013-02-19 15:55:16


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
WHT Host Brief Email:

We respect your privacy. We will never sell, rent, or give away your address to any outside party, ever.

Advertisement:
Web Hosting News:
WHT Membership
WHT Membership



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?