Database Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesDatabase Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old September 28th, 2003, 08:23 PM
CZealot CZealot is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 3 CZealot User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
What does this query mean ?

Hello,
I am browsing the code of Invision Board v. 1.2 as I need to add some fileds to it.
So there is a Query to DB, that selects some fields, and that are used in Topics (Avatar, Post Count etc). I need that this query selected some other fileds from other table, but first I must understand how it works...
Heres the query:

$DB->query( "SELECT p.*,
m.id,m.name,m.mgroup,m.email,m.joined,m.avatar,m.a vatar_size,m.posts,m.aim_name,m.icq_number,
m.signature, m.website,m.yahoo,m.integ_msg,m.title,m.hide_email ,m.msnname, m.warn_level, m.warn_lastwarn,
g.g_id, g.g_title, g.g_icon, g.g_dohtml $join_get_fields
FROM ibf_posts p
LEFT JOIN ibf_members m ON (p.author_id=m.id)
LEFT JOIN ibf_groups g ON (g.g_id=m.mgroup)
$join_profile_query
WHERE p.topic_id=".$this->topic['tid']." and p.queued != 1
ORDER BY p.pid LIMIT $first, ".$ibforums->vars['display_max_posts']);

Heres the ibf_posts and ibf_members table structure:

mysql> describe ibf_posts;
+-------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+----------------+
| pid | int(10) | | PRI | NULL | auto_increment |
| append_edit | tinyint(1) | YES | | 0 | |
| edit_time | int(10) | YES | | NULL | |
| author_id | mediumint(8) | | MUL | 0 | |
| author_name | varchar(32) | YES | | NULL | |
| use_sig | tinyint(1) | | | 0 | |
| use_emo | tinyint(1) | | | 0 | |
| ip_address | varchar(16) | | | | |
| post_date | int(10) | YES | | NULL | |
| icon_id | smallint(3) | YES | | NULL | |
| post | text | YES | MUL | NULL | |
| queued | tinyint(1) | YES | | NULL | |
| topic_id | int(10) | | MUL | 0 | |
| forum_id | smallint(5) | | MUL | 0 | |
| attach_id | varchar(64) | YES | | NULL | |
| attach_hits | int(10) | YES | | NULL | |
| attach_type | varchar(128) | YES | | NULL | |
| attach_file | varchar(255) | YES | | NULL | |
| post_title | varchar(255) | YES | | NULL | |
| new_topic | tinyint(1) | YES | | 0 | |
| edit_name | varchar(255) | YES | | NULL | |
+-------------+--------------+------+-----+---------+----------------+
21 rows in set (0.00 sec)

mysql> describe ibf_members;
+-------------------+-----------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------------+-----------------------+------+-----+---------+-------+
| id | mediumint(8) | | PRI | 0 | |
| name | varchar(255) | | MUL | | |
| mgroup | smallint(3) | | MUL | 0 | |
| password | varchar(255) | | | | |
| email | varchar(255) | | | | |
| joined | int(10) | | | 0 | |
| ip_address | varchar(16) | | | | |
| avatar | varchar(128) | YES | | NULL | |
| avatar_size | varchar(9) | YES | | NULL | |
| posts | mediumint(7) | YES | | 0 | |
| aim_name | varchar(40) | YES | | NULL | |
| icq_number | varchar(40) | YES | | NULL | |
| location | varchar(128) | YES | | NULL | |
| signature | text | YES | | NULL | |
| website | varchar(70) | YES | | NULL | |
| yahoo | varchar(32) | YES | | NULL | |
| title | varchar(64) | YES | | NULL | |
| allow_admin_mails | tinyint(1) | YES | | NULL | |
| time_offset | varchar(10) | YES | | NULL | |
| interests | text | YES | | NULL | |
| hide_email | varchar(8) | YES | | NULL | |
| email_pm | tinyint(1) | YES | | NULL | |
| email_full | tinyint(1) | YES | | NULL | |
| skin | smallint(5) | YES | | NULL | |
| warn_level | int(10) | YES | | NULL | |
| warn_lastwarn | int(10) | | | 0 | |
| language | varchar(32) | YES | | NULL | |
| msnname | varchar(64) | YES | | NULL | |
| last_post | int(10) | YES | | NULL | |
| restrict_post | varchar(100) | | | 0 | |
| view_sigs | tinyint(1) | YES | | 1 | |
| view_img | tinyint(1) | YES | | 1 | |
| view_avs | tinyint(1) | YES | | 1 | |
| view_pop | tinyint(1) | YES | | 1 | |
| bday_day | int(2) | YES | MUL | NULL | |
| bday_month | int(2) | YES | MUL | NULL | |
| bday_year | int(4) | YES | | NULL | |
| new_msg | tinyint(2) | YES | | NULL | |
| msg_from_id | mediumint(8) | YES | | NULL | |
| msg_msg_id | int(10) | YES | | NULL | |
| msg_total | smallint(5) | YES | | NULL | |
| vdirs | text | YES | | NULL | |
| show_popup | tinyint(1) | YES | | NULL | |
| misc | varchar(128) | YES | | NULL | |
| last_visit | int(10) | YES | | 0 | |
| last_activity | int(10) | YES | | 0 | |
| dst_in_use | tinyint(1) | YES | | 0 | |
| view_prefs | varchar(64) | YES | | -1&-1 | |
| coppa_user | tinyint(1) | YES | | 0 | |
| mod_posts | varchar(100) | | | 0 | |
| auto_track | tinyint(1) | YES | | 0 | |
| org_perm_id | varchar(255) | YES | | | |
| org_supmod | tinyint(1) | YES | | 0 | |
| integ_msg | varchar(250) | YES | | | |
| temp_ban | varchar(100) | YES | | NULL | |
| clanid | mediumint(8) unsigned | | | 0 | |
| clanname | varchar(20) | | | 0 | |
| wins | mediumint(8) unsigned | | | 0 | |
| losses | mediumint(8) | | | 0 | |
| tcpoints | mediumint(8) unsigned | | | 0 | |
| streak | mediumint(8) unsigned | | | 0 | |
| totalgames | mediumint(8) unsigned | | | 0 | |
| lastgame | varchar(30) | | | 0 | |
+-------------------+-----------------------+------+-----+---------+-------+
63 rows in set (0.00 sec)

Why m.X(m.id,m.name) are used in this query ? What does p. , m. and g. mean ?
And what exactly does LEFT JOIN ibf_members m ON (p.author_id=m.id) do ?
I would be thankfull for any information you can provide,
CZealot

Reply With Quote
  #2  
Old September 28th, 2003, 09:42 PM
honcho's Avatar
honcho honcho is offline
Contributing User
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: Apr 2007
Location: Cape Cod
Posts: 1,347 honcho User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 52 m 2 sec
Reputation Power: 4
RE: What does this query mean ?

Quote:
Why m.X(m.id,m.name) are used in this query?


I'm not sure I understand what you are asking. If you're wondering why m.id, m.name, etc. are being selected, it's presumably because those values are used in the page.

Quote:
What does p. , m. and g. mean ?


These are all table aliases.
p = ibf_posts
m = ibf_members
g = ibf_groups

Quote:
And what exactly does LEFT JOIN ibf_members m ON (p.author_id=m.id) do ?


This includes a row of data (if it exists) from the ibf_members table. The row is the one where the id column of ibf_members (m.id) is the same as the author_id column in the ibf_posts table (p.author_id). This also assigns the alias "m" to the ibf_members table.

I suggest you get a book about SQL.

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesDatabase Help > What does this query mean ?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
Create the Optimal Architecture for your Critical Applications
Warburton's the largest independently owned bakery in the UK faced a number of difficult challenges in providing the most robust yet efficient IT infrastructure for their organization's success. IBM's services combined with their xSeries servers created the perfect platform for their SAP environment with sufficient flexibility, and did so in very time effective fashion.

Request Your Free Technology Downloads!
 
Five Best Practices for Deploying a Successful Service-Oriented Architecture
This white paper describes the benefits you can expect with SOA, and how IBM can help take your business there.

Request Your Free Technology Downloads!
 
Gartner Magic Quadrant for Application Delivery Controllers
Gartner summarizes its view on Application Delivery Controllers, evaluates strengths and weaknesses of solutions, and provides Magic Quadrant reporting for a quick comparison across all vendors. Learn from Gartner how you can benefit from an all-in-one device like Citrix NetScaler that delivers the highest levels of availability, performance and security.

Request Your Free Technology Downloads!
 
Knowledge is Power
What you don't know can hurt you, and is likely costing you money and increasing your security risks during an era of scarce resources. This white paper proposes six key strategies that enterprise security managers can use to improve their network defense posture.

Request Your Free Technology Downloads!
 
Rationalizing the Multi-Tool Environment
The rationalized multi-tool approach is flexible, scalable and cost effective. It provides the necessary input to the IT service management business processes. It preserves prior investments in monitoring tools, empowers technologists to select the best tools with which to do their jobs, and enhances effective response to incidents.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2010 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek