Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Professional WordPress
This is the forum to discuss the Wrox book Professional WordPress by Hal Stern, David Damstra, Brad Williams; ISBN: 9780470560549
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional WordPress section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old July 16th, 2010, 06:39 AM
Registered User
 
Join Date: Jul 2010
Location: Singapore
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Default Database queries

Hi,

I've found this book immensely helpful towards understanding what makes Wordpress tick. You guys are great.

I've got a question about the MySQL command line examples on page 113:

Code:
SELECT wc.* FROM wp_posts wp 
INNER JOIN wp_comments wc ON wp.ID = wc.comment_post_ID 
WHERE wp.ID = ‘1554’
I didn't understand the part about wc.* because there don't seem to be any tables or columns with a wc- prefix. Couldn't get anything useful with Googling it either. I think I'm lost in figuring this one out.

Thanks for any help.
Reply With Quote
  #2 (permalink)  
Old July 17th, 2010, 11:12 AM
Wrox Author
 
Join Date: Mar 2010
Location: New Jersey
Posts: 6
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Robert,

wc in the query example you posted is a short way of referencing the wp_comments table in your query. In that example we are also referencing wp_posts using wp. This is just a quick and easy way to make a short reference to a table name. Here's another example:

PHP Code:
SELECT FROM wp_posts wp WHERE wp.ID '5' 
Notice how I set wp directly after I define the table name to access. Once I have defined wp I can use it going forward (wp.ID is the same as wp_posts.ID).
Reply With Quote
  #3 (permalink)  
Old July 17th, 2010, 12:24 PM
Registered User
 
Join Date: Jul 2010
Location: Singapore
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Hi Brad,

Firstly, is that the same as:

Code:
SELECT * FROM wp_posts AS wp WHERE wp.ID = '5'
Secondly, what does the .* after
Code:
SELECT wc.*
do?

Thanks for answering my questions, I'm very new to all this database stuff.
Reply With Quote
  #4 (permalink)  
Old July 17th, 2010, 12:29 PM
Wrox Author
 
Join Date: Mar 2010
Location: New Jersey
Posts: 6
Thanks: 0
Thanked 1 Time in 1 Post
Default

Yes they are the same, it's basically an alias for the table name.

wc.*, or just *, selects all fields from a given table. So this query:

PHP Code:
SELECT FROM wp_posts 
Would retrieve all records and all fields in the wp_posts table. Generally it's best to define exactly what fields you need for optimization reasons like so:

PHP Code:
SELECT IDpost_title FROM wp_posts 
Reply With Quote
The Following User Says Thank You to williamsba For This Useful Post:
robertgreen (July 17th, 2010)
  #5 (permalink)  
Old July 17th, 2010, 12:38 PM
Registered User
 
Join Date: Jul 2010
Location: Singapore
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Thanks, Brad. That was helpful. :)
Reply With Quote
Reply


Thread Tools
Display Modes

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
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Database diagrams (aka Queries) Steve1977 BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 1 September 14th, 2008 07:06 AM
using @cursor in Perl database queries crmpicco Perl 0 March 2nd, 2007 07:33 AM
newbie...database queries.. Deepa7476 Visual Basic 2005 Basics 2 June 16th, 2006 12:41 AM
Database Queries frosty ASP.NET 2.0 Basics 3 May 13th, 2006 06:20 PM
Queries on Back End database? gazolba Access 3 May 1st, 2004 11:30 AM



All times are GMT -4. The time now is 03:41 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.