473,480 Members | 3,017 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Mysql Select problem

Hi

Currently im using this

$query = "select * from news, users where news.User_ID = users.User_ID order
by news.News_ID DESC"

only problem is both tables have User_ID, how can I make aliases of these?

Donno how to do it :S
Jul 17 '05 #1
6 1742

On 19-Mar-2004, "Hayden Kirk" <sp**@spam.com> wrote:
Currently im using this

$query = "select * from news, users where news.User_ID = users.User_ID
order
by news.News_ID DESC"

only problem is both tables have User_ID, how can I make aliases of these?


select news.User_ID as userid, * from ...

--
Tom Thackrey
www.creative-light.com
tom (at) creative (dash) light (dot) com
do NOT send email to ja*********@willglen.net (it's reserved for spammers)
Jul 17 '05 #2
Can you give me an exampl, I cant get it :(

Thanks,
Hayden

"Tom Thackrey" <us***********@nospam.com> wrote in message
news:BZ*******************@newssvr29.news.prodigy. com...

On 19-Mar-2004, "Hayden Kirk" <sp**@spam.com> wrote:
Currently im using this

$query = "select * from news, users where news.User_ID = users.User_ID
order
by news.News_ID DESC"

only problem is both tables have User_ID, how can I make aliases of
these?
select news.User_ID as userid, * from ...

--
Tom Thackrey
www.creative-light.com
tom (at) creative (dash) light (dot) com
do NOT send email to ja*********@willglen.net (it's reserved for spammers)

Jul 17 '05 #3

On 20-Mar-2004, "Hayden Kirk" <sp**@spam.com> wrote:
"Tom Thackrey" <us***********@nospam.com> wrote in message
news:BZ*******************@newssvr29.news.prodigy. com...

On 19-Mar-2004, "Hayden Kirk" <sp**@spam.com> wrote:
Currently im using this

$query = "select * from news, users where news.User_ID = users.User_ID
order
by news.News_ID DESC"

only problem is both tables have User_ID, how can I make aliases of

these?

select news.User_ID as userid, * from ...

Can you give me an exampl, I cant get it :(


$query = "select news.User_ID as userid,* from news,users where
news.UserID=users.UserID order by news.News_ID desc";

When you fetch the results the value of news.UserID will be in the result
array as index ['userid'] (or [0])
--
Tom Thackrey
www.creative-light.com
tom (at) creative (dash) light (dot) com
do NOT send email to ja*********@willglen.net (it's reserved for spammers)
Jul 17 '05 #4
Tom Thackrey wrote:
On 19-Mar-2004, "Hayden Kirk" <sp**@spam.com> wrote:

Currently im using this

$query = "select * from news, users where news.User_ID = users.User_ID
order
by news.News_ID DESC"

only problem is both tables have User_ID, how can I make aliases of these?

select news.User_ID as userid, * from ...

Since the WHERE clause is making them equal it does not matter which
variable ends up in the Select list; both is ok too. In order to better
abbreviate the WHERE predicates you could correlate the tables to an
alias.

$query = "select * from news a, users b where a.User_ID = b.User_ID
order by a.News_ID DESC"

What particular problem were you having?
Not absolutely sure of the syntax....you MAY need the AS keyword for the
correlation variable: ... news AS a, users AS b ....

Disclaimer: Not tested

Chris
Always remember, you are unique...just like everyone else.
Jul 17 '05 #5
Thanks both, been a great help.

The problem I was having is what if I wanted to get both User_ID's from both
tables... the array is only going to hold one of them.

So I was wondering If I could use an alias, but everything I tried I got
errors. So far this is what I have:

select * from users, news where users.User_ID = news.User_ID order by
news.News_ID DESC;

But there will only be one User_ID in my array... how would I change this to
make an alias? So like News.User_ID, User.User_ID?

Maybe I should have a seperate table to take this out of the news table as
it shouldn't really be there, compound enitity :S

"pomasl<nospam> @starband.net>" <"pomasl<nospam> wrote in message
news:GU****************@fe25.usenetserver.com...
Tom Thackrey wrote:
On 19-Mar-2004, "Hayden Kirk" <sp**@spam.com> wrote:

Currently im using this

$query = "select * from news, users where news.User_ID = users.User_ID
order
by news.News_ID DESC"

only problem is both tables have User_ID, how can I make aliases of
these?

select news.User_ID as userid, * from ...

Since the WHERE clause is making them equal it does not matter which
variable ends up in the Select list; both is ok too. In order to better
abbreviate the WHERE predicates you could correlate the tables to an
alias.

$query = "select * from news a, users b where a.User_ID = b.User_ID
order by a.News_ID DESC"

What particular problem were you having?
Not absolutely sure of the syntax....you MAY need the AS keyword for the
correlation variable: ... news AS a, users AS b ....

Disclaimer: Not tested

Chris
Always remember, you are unique...just like everyone else.

Jul 17 '05 #6

On 21-Mar-2004, "Hayden Kirk" <sp**@spam.com> wrote:
The problem I was having is what if I wanted to get both User_ID's from
both
tables... the array is only going to hold one of them.

So I was wondering If I could use an alias, but everything I tried I got
errors. So far this is what I have:

select * from users, news where users.User_ID = news.User_ID order by
news.News_ID DESC;

But there will only be one User_ID in my array... how would I change this
to
make an alias? So like News.User_ID, User.User_ID?


I think I answered your question before, but here it is again

select users.User_ID as userid, * from ...

This will create an extra column called userid which will contain
users.User_ID.

You say you want both users.User_ID and news.User_ID but your select will
ensure they have the same value, so why do you need both??

If you really want both you would code something like

select users.User_ID as usersuserid, news.User_ID as newsuserid, * from...

This will create two extra columns, usersuserid and newsuserid.

--
Tom Thackrey
www.creative-light.com
tom (at) creative (dash) light (dot) com
do NOT send email to ja*********@willglen.net (it's reserved for spammers)
Jul 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
4473
by: Bert Sierra | last post by:
Hello -- I have what appears to be a simple PHP+MySQL query, but Dreamweaver consistently generates PHP code which won't parse. I've stared at the PHP code for several hours now, and I can't...
0
3506
by: Lenz Grimmer | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, MySQL 4.0.14, a new version of the popular Open Source/Free Software Database, has been released. It is now available in source and binary...
5
3984
by: red85 | last post by:
hello i have mysql 4.1 with win2000 SP3, i know that it is only an alpha and i don't know if someone else has already posted this problem: when i execute this sql UPDATE tableX SET...
0
4978
by: Fatt Shin | last post by:
Hi, I'm running MySQL 4.0.13, connecting from PowerBuilder 9 using ODCB Connector 3.51. I'm facing a problem where whenever I issue a SELECT COUNT(*) statement from PowerBuilder, I always get SQL...
0
3922
by: Mike Chirico | last post by:
Interesting Things to Know about MySQL Mike Chirico (mchirico@users.sourceforge.net) Copyright (GPU Free Documentation License) 2004 Last Updated: Mon Jun 7 10:37:28 EDT 2004 The latest...
1
3357
by: jlee | last post by:
I'm pretty much a newbie on mysql, and I need some help. I am running mysql Ver 12.22 Distrib 4.0.24, for portbld-freebsd5.4 (i386) on a server hosting an active website. The site's developer...
8
2337
by: Fred | last post by:
Hello, Our website is currently developed in ASP/Mysql 4. The dedicated servers on which it is currently hosted arrive at saturation. Here is their configuration: - 1 server PIV 2,8Ghz 1GB...
0
19248
by: IamtheEvster | last post by:
Hi All, I am currently using PHP 5 and MySQL 5, both on Fedora Core 5. I am unable to call a MySQL stored procedure that returns output parameters using mysql, mysqli, or PDO. I'm having a...
1
4829
by: jrs_14618 | last post by:
Hello All, This post is essentially a reply a previous post/thread here on this mailing.database.myodbc group titled: MySQL 4.0, FULL-TEXT Indexing and Search Arabic Data, Unicode I was...
6
1481
by: ojorus | last post by:
Hi! My company make several flash-based games, and I use php to communicate with mysql to provide highscore-lists. My problem is this: When I save a player's score in the mysql-table, I want to...
0
7055
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6920
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7060
Oralloy
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,...
0
7106
jinu1996
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...
1
6760
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7022
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4501
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3004
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
572
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.