473,396 Members | 2,002 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Easier way to do this

I have 3 tables with a id column in each matching

1. contact
2. personalinfo
3. photos

i want to query the personalinfo database :

SELECT *
FROM `talent_personalinfo`
WHERE `gender` = 'Female'
AND `nationality` = 'Australia'
AND `race` = 'Australian/European'

this is great. but I also want to get the information from the other
tables where the id from the returned values matches. isnt there some
fancy join that can do it for me? if I add the other tables into the
WHERE line, it just returns all the rows for as how many results i
have x 2

at the moment i'd have to query the first database, getting the id in
an array, then query them individual where the id = $arr[x]; loop

any help appreciated
cheerio
Jul 20 '05 #1
1 1045
RelaxoRy wrote:
I have 3 tables with a id column in each matching

1. contact
2. personalinfo
3. photos

i want to query the personalinfo database :

SELECT *
FROM `talent_personalinfo`
WHERE `gender` = 'Female'
AND `nationality` = 'Australia'
AND `race` = 'Australian/European'

this is great. but I also want to get the information from the other
tables where the id from the returned values matches. isnt there some
fancy join that can do it for me? if I add the other tables into the
WHERE line, it just returns all the rows for as how many results i
have x 2

at the moment i'd have to query the first database, getting the id in
an array, then query them individual where the id = $arr[x]; loop

any help appreciated
cheerio


I'm a newbie... but you could try something like:

SELECT * FROM personalinfo, contact, photos
WHERE gender='Female'
AND nationality='Australia'
AND race='Australian/European'
AND personalinfo.id=contact.id
AND contact.id=photos.id

NOTE: Because the 'id' columns are common in all tables, you will get an
error because the SELECT * will get id from the three different tables
and get its knicers in a twist. The solution for this is to
specifically name the columns you want... Thus, you could change the
first line in the SELECT above to something like

SELECT personalinfo.id as pid, personalinfo.firstname,
personalinfo.whatever, contact.id as cid, contact.tel, photos.id as fid,
photos.somethingelse
WHERE ....
Note the usage of 'as' in the SELECT - This allows you to refer to
personalinfo.id as pid and remove duplicity...

I hope that helps - and I hope my syntax is correct too...

Note, what steps have you put in place to ensure the ID numbers of each
record retain the relationship with each other? If you were to add two
records at the same time, its possible that the server could give you a
mis-match (thus, for example, the complete data for personalinfo.id=1
might continue in contact.id=2 and photos.id=2).

To resolve this, use a foreign key that is inserted in to all three
records, and common (use an md5 hash forexample).

I hope this helps,

randelld
Jul 20 '05 #2

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

Similar topics

3
by: NotGiven | last post by:
I am researching the best place to put pictures. I have heard form both sides and I'd like to know why one is better than the other. Many thanks!
17
by: Rob | last post by:
i know javascript, vbscript, asp css and alot more and im only 14 i was wondering which is easier to learn php or cgi. any help?
15
by: Herman | last post by:
Hi everyone, I'm currently studying for my Master's in Computer Science, and I will be working on my thesis this summer. I've been thinking about constructing a web services application for my...
1
by: Kenneth McDonald | last post by:
I'm working on the 0.8 release of my 'rex' module, and would appreciate feedback, suggestions, and criticism as I work towards finalizing the API and feature sets. rex is a module intended to make...
13
by: cjl | last post by:
Hey all: I'm working on a 'pure' python port of some existing software. Implementations of what I'm trying to accomplish are available (open source) in C++ and in Java. Which would be...
2
by: Mario T. Lanza | last post by:
Greetings, I have been developing websites in CSS for a couple years; I claim to be no expert, but certain things could definitely be easier. Consider the box model and it's different...
1
by: Peter | last post by:
Hello, Thanks for reviewing my question. I would like to know if there is an easier way to regenerate your dataset in VS.NET when your database schema changes. I am frequently add or remove...
0
by: Peter | last post by:
Hello, Thanks for reviewing my question. I would like to know if there is an easier way to regenerate your dataset in VS.NET when your database schema changes. I am frequently add or remove...
66
by: Mitchell S. Honnert | last post by:
In some recent posts, I've seen people who seem to be waxing nostalgic with respect to the "ease of use" of Visual Basic 6. I can't quite put my finger on it, but they seem to be implying that VB6...
13
by: dm1608 | last post by:
I know all the hype right now from Microsoft is how much easier, faster, and less code ASP.NET 2.0 provides over previous versions. I'm puzzled by this as I could turn out an classic ASP webpage...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
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
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
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...
0
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
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...

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.