Hi
I'm making a good ol' forum, and i have three tables, users, threads
and posts. when i query my threads table with a join, i need to access
the users table twice to get the username of the first poster and last
poster. But how? I can only figure out how to get one or the other. Is
my design bad? eg
SELECT TopicID, FirstPostID, LastPostID, Replies, Views, Topic,
username FROM DiscussionThreads, users WHERE
DiscussionThreads.FirstPostID=users.ID ORDER BY FirstPostDT DESC LIMIT
10
any help appreciated
cheers
dave 3 1485
<ma**********@hotmail.com> skrev i en meddelelse
news:ci********@odak26.prod.google.com... Hi
I'm making a good ol' forum, and i have three tables, users, threads and posts. when i query my threads table with a join, i need to access the users table twice to get the username of the first poster and last poster. But how? I can only figure out how to get one or the other. Is my design bad? eg
SELECT TopicID, FirstPostID, LastPostID, Replies, Views, Topic, username FROM DiscussionThreads, users WHERE DiscussionThreads.FirstPostID=users.ID ORDER BY FirstPostDT DESC LIMIT 10
Use aliases:
select ... , firstposter´.name,lastposter.name from DiscussionThreads as
dt,users as firstposter, users as lastposter
where dt.firstpostid=firstposter.id
and dt.lastpostid=lastposter.id
You use the same table twice with two different names.
Leif
"Leif" <id****@internet.dk> wrote in message Use aliases:
select ... , firstposter´.name,lastposter.name from DiscussionThreads as dt,users as firstposter, users as lastposter where dt.firstpostid=firstposter.id and dt.lastpostid=lastposter.id
You use the same table twice with two different names.
OK, makes sense. But my resultant object, how would i fetch my
results? THat is, would $result->name return the firstname or the last
name? how do i go about giving the resultant usernames an alias?
cheers
dave
mammothman42 wrote: how do i go about giving the resultant usernames an alias?
SQL allows you to assign column aliases, just as it allows you to assign
table aliases.
select firstposter.name AS firstposter_name,
lastposter.name AS lastposter_name
....
Regards,
Bill K. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Prem |
last post by:
Hi,
I am having many problems with inner join. my first problem is :
1) I want to know the precedance while evaluating query with multiple
joins.
eg.
select Employees.FirstName,...
|
by: Don |
last post by:
I am trying to use SQL to return data from multiple tables at the same time.
My first table is keyed on SSN. This table has an ID field in it. I will
use this ID to find matching rows in 4 other...
|
by: Ed_No_Spam_Please_Weber |
last post by:
Hello All & Thanks in advance for your help!
Background:
1) tblT_Documents is the primary parent transaction table that has 10
fields and about 250,000 rows
2) There are 9 child tables with...
|
by: jbm05 |
last post by:
Hi,
I'm curious about the computational complexity of a query I have. The
query contains multiple nested self left joins, starting with a simple
select, then doing a self left join with the...
|
by: Steve |
last post by:
I have a SQL query I'm invoking via VB6 & ADO 2.8, that requires three
"Left Outer Joins" in order to return every transaction for a specific
set of criteria.
Using three "Left Outer Joins"...
|
by: p175 |
last post by:
Hi people,
I have a stored procedure that creates many Global temporary
session tables. Into each of these tables go the results of various
processing using relational division all keyed and...
|
by: ankush |
last post by:
I have a table heirarchy of around 5 tables. At places where i have to do a search with criteria ranging on all these tables, will it be advisable to have a join on all the tables. A couple of tables...
|
by: nathj |
last post by:
Hi,
I've been puzzling out the problem below for several hours and it's driving me mad. I know there is a way to do what I want I just can't figure it out.
Here's the situation. I have the...
|
by: beargrease |
last post by:
I'm kind of comfortable with basic joins, but a current project requires a complex query of many tables. The GROUP_CONCAT(DISTINCT ...) function has been very useful as returning my values as comma...
|
by: Bogdan |
last post by:
Hi,
I have a stored procedure that uses JOINs to return columns from multiple
tables. I also have another stored proc that that takes a series of params
and updates multiple tables. I used the...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |