Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 16th, 2010, 06:39 AM
Registered User
 
Join Date: Jul 2010
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.
 
Old July 17th, 2010, 11:12 AM
Wrox Author
 
Join Date: Mar 2010
Posts: 7
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).
 
Old July 17th, 2010, 12:24 PM
Registered User
 
Join Date: Jul 2010
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.
 
Old July 17th, 2010, 12:29 PM
Wrox Author
 
Join Date: Mar 2010
Posts: 7
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 
The Following User Says Thank You to williamsba For This Useful Post:
robertgreen (July 17th, 2010)
 
Old July 17th, 2010, 12:38 PM
Registered User
 
Join Date: Jul 2010
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Thanks, Brad. That was helpful. :)





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 08: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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.