Experts Round Table Network
Navigate
Home
ArticleWiki
Forum
Journal
Search
Newsletter
Links
Tech News
expertsrt.com
Welcome Guest.
Username:
Password:
Remember me
Forgot your password?
Register
querying multiple tables--where to start?
Welcome,
Guest
. Please
login
or
register
.
December 01, 2008, 06:21:37 PM
11304
Posts in
1248
Topics by
496
Members
Latest Member:
teentiodo
Home
Help
Search
Login
Register
Experts Round Table Network
|
Databases
|
MySQL
|
querying multiple tables--where to start?
« previous
next »
Pages:
[
1
]
Print
Author
Topic: querying multiple tables--where to start? (Read 324 times)
klitscher
Offline
Posts: 24
querying multiple tables--where to start?
«
on:
August 02, 2006, 04:10:12 PM »
Hello,
I am writing some code (using php) to create a website that will allow users to post news and events and am coming up with the MYSQL backend now. I am using 4 tables to start....one will contain the users info, one will contain the posts, one will contain the different groups the posts will be organized by (news, Family events, sports, etc) and the final one will be a linking table between the groups and the posts containing two fields, group_id and post_id (this is because each post can be filed under multiple groups). So, what I want to do is select the 5 most recent posts (or the five closest upcoming events) of any given group and display the information, including info about the user who posted it and I don't know where to start.
I would assume I would first query the group_post_link table to find all of the posts under a certain group, then query the post table to find the 5 applicable posts, and then query the user table to get all of the information...but I'm not sure where to start or what would be the best (read: fastest and easiest, not necessarily in that order) way to do it. I've tried mysql.org, but I'm not sure what I should be looking for. Any help would be greatly appreciated.
Logged
COBOLdinosaur
ERT.com Admin
Offline
Posts: 481
Re: querying multiple tables--where to start?
«
Reply #1 on:
August 02, 2006, 07:45:49 PM »
Assuming the posts table has the user id associated with it then you should be able to select the user infomation and post information in a single query by crossing the table on the user id key. So if you select the applicable columns from the user and posts table where the user id on the user table and post table match and the post id matches the cross-reference in the group/posts table, then you simply order on the timestamp, and use a limit of 5 to only return the first 5 rows of the data set.
Logged
klitscher
Offline
Posts: 24
Re: querying multiple tables--where to start?
«
Reply #2 on:
August 02, 2006, 10:21:37 PM »
Thanks...that helped out a lot and I've figured out how to do it...I just didn't know what terms to google, and cross join and query multiple tables did it...Thanks again
Ken
Logged
COBOLdinosaur
ERT.com Admin
Offline
Posts: 481
Re: querying multiple tables--where to start?
«
Reply #3 on:
August 03, 2006, 06:46:31 AM »
Yeah, finding the right search term is sometimes the hardest part of solving a problem. Glad I could help.
Logged
Pages:
[
1
]
Print
« previous
next »
Jump to:
Please select a destination:
-----------------------------
ERT 1.5
-----------------------------
=> Round Table Learning Center
=> Bug reports
-----------------------------
Legacy
-----------------------------
=> The next level
=> History of ERT
-----------------------------
Community Affairs
-----------------------------
=> Introductions
=> Ballot Box
===> Closed Polls
=> Soapbox
=> Propose and Consult
===> Propose and Consult...CLOSED
-----------------------------
Bits and Bytes
-----------------------------
=> Tips, Tricks, Snippets, Tidbits And General Pearls Of Wisdom
-----------------------------
Serverside Technology
-----------------------------
=> PHP
=> ASP
-----------------------------
Webservers
-----------------------------
=> Apache
=> IIS
-----------------------------
Databases
-----------------------------
=> MySQL
=> Access
=> MS SQL Server
-----------------------------
Clientside Technology
-----------------------------
=> HTML
=> CSS
=> Javascript
=> Flash
=> WAP/WML
-----------------------------
Web Technologies
-----------------------------
=> General Web Dev
=> Web Standards
=> XML
=> Online Marketing
-----------------------------
Graphics
-----------------------------
=> Graphics Design and Animation
-----------------------------
Programming
-----------------------------
=> .NET
=> JAVA
=> MS DOS Batch Scripting
=> Mathematics
=> C & C++
=> VB
=> Delphi
=> Algorithm design
-----------------------------
Operating Systems
-----------------------------
=> Windows (General)
=> NT Based (2K, 2K-03, NT, XP, Vista)
=> Open Source (All)
-----------------------------
Hardware
-----------------------------
=> Hardware General
=> Gamers Hardware (Advanced)
-----------------------------
Networking
-----------------------------
=> Home (small)
=> Office (large)
=> Internet
-----------------------------
Security
-----------------------------
=> General Security Issues
-----------------------------
Rants/Opinions/Proposals
-----------------------------
=> Site operation
Powered by SMF 1.1 RC2
|
SMF © 2001-2005, Lewis Media
Joomla Bridge by
JoomlaHacks.com