473,606 Members | 2,101 Online
Bytes | Software Development & Data Engineering Community
+ 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 1749

On 19-Mar-2004, "Hayden Kirk" <sp**@spam.co m> 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*********@wil lglen.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******** ***********@new ssvr29.news.pro digy.com...

On 19-Mar-2004, "Hayden Kirk" <sp**@spam.co m> 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*********@wil lglen.net (it's reserved for spammers)

Jul 17 '05 #3

On 20-Mar-2004, "Hayden Kirk" <sp**@spam.co m> wrote:
"Tom Thackrey" <us***********@ nospam.com> wrote in message
news:BZ******** ***********@new ssvr29.news.pro digy.com...

On 19-Mar-2004, "Hayden Kirk" <sp**@spam.co m> 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=use rs.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*********@wil lglen.net (it's reserved for spammers)
Jul 17 '05 #4
Tom Thackrey wrote:
On 19-Mar-2004, "Hayden Kirk" <sp**@spam.co m> 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<nos pam> @starband.net>" <"pomasl<nospam > wrote in message
news:GU******** ********@fe25.u senetserver.com ...
Tom Thackrey wrote:
On 19-Mar-2004, "Hayden Kirk" <sp**@spam.co m> 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.co m> 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*********@wil lglen.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
4484
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 see the problem. Thanks in advance for any input you might have to the problem.
0
3515
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 form for a number of platforms from our download pages at http://www.mysql.com/downloads/ and mirror sites.
5
3993
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 fieldX=valueX WHERE id IN (SELECT tX.id FROM tableX AS tX WHERE tX.fieldY=valueY AND filedZ=valueZ);
0
4987
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 syntax error back from MySQL. (Refer to ODBC Trace I captured below). metrohouse af8-b94 ENTER SQLExecDirect HSTMT 014D2360 UCHAR * 0x020A0EA2 "select count ( *) from code
0
3938
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 version of this document can be found at: http://prdownloads.sourceforge.net/souptonuts/README_mysql.txt?download
1
3366
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 uses his own php shopping cart to receive customer orders. The configuration was done via cPanel with no external modifications - which produced no protests when built, ran and connected with no
8
2354
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 RAM with IIS 5 on Windows 2000 - 1 server Bi-xeon 3Ghz, 512 MB with MySQL 4 on Windows 2003 The website makes approximately 10.000.000 of pages seen and 310.000
0
19271
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 hell of a time with it... The following comes from phpinfo(): PHP Version: 5.1.2 mysql Client API version: 5.0.18 mysqli Client API version: 5.0.18
1
4839
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 wondering if anybody has experienced the same issues
6
1489
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 find which place the player got with his score (today). To get this I have tried two different solutions, which both works, but are very ineffective: (The Time-field is a DateTime type, and I have Score and Time as Indexes)
0
8010
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7942
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8433
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8429
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8300
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6761
agi2029
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5461
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3922
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
1287
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.