473,382 Members | 1,329 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,382 software developers and data experts.

sub queries in mysql?

------=_NextPart_000_0075_01C36186.A832CF80
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit

Hello,

Is there a way to do something like subqueries in one query?

I have a customer table (Klant) with contacts (KlantKontakt) and a
address (Adres) table.
The address table keeps a record of each different address for a
customer including old addresses (to maintain history).

If I want to retrieve a list of customers with their newest address, I
have to do a max() to retreive the last address.
I can do this in PHP in a seperate query but I like to do it in one
query on the mysql prompt.

Below is my (wrong) query:

SELECT
Klant.klantcode, Klant.naam,
KlantKontakt.persooncode, KlantKontakt.Achternaam,
Adres.straat, Adres.postcode, Adres.plaats

FROM Klant, KlantKontakt, Adres

WHERE SoortKlant = 'Prospect'
AND Klant.klantcode = KlantKontakt.klantcode
AND Adres.klantcode = Klant.klantcode

ORDER BY Klant.Naam
Is there any way to do this in MySQL in one query?
Regards,

Jasper Bijl

------=_NextPart_000_0075_01C36186.A832CF80--

Jul 19 '05 #1
0 1078

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

Similar topics

4
by: Phil Powell | last post by:
http://www.php.net/array_filter I went there at first for my information on filtering mySQL query results using PHP, to no avail. This is more of a Vignette construct (my native environment)...
3
by: Mark Stevens | last post by:
I am trying to do select all of the records in a table where they data has not expired. The table contains two fields Subject (varchar(100)) and ExpiryDate (Date). I am getting all of the...
0
by: Morten Gulbrandsen | last post by:
Dear mysql users, in the tutorial of the documentation I found an interesting example of a complicated non trivial sql query: URL:...
9
by: Timo | last post by:
I just got a new dual opteron system, with raid 01, 2gb ram, and fedora core linux running 2.4.22-smp kernel. For some reason mysql is running pathetically slow. Queries that should take 2ms...
1
by: Henry | last post by:
I have two tables, one is Student, which has studentid, personid, grade, fees as its columns. The other one is Person, which has personid, firstname, lastname, address as its columns. When given...
5
by: My SQL | last post by:
Hi, I started the general query log with mysqld --log On my machine this command works fine and every select, update and all statements are logged. I tried the same command on another...
1
by: Good Man | last post by:
Hi there I've noticed some very weird things happening with my current MySQL setup on my XP Laptop, a development machine. For a while, I have been trying to get the MySQL cache to work....
10
by: tuco357 | last post by:
This problem has been vexing me for some time and I thought I should consult the group.... Often times when writing a php script to handle some mysql DB transactions, I must write code that...
1
by: thinkingman | last post by:
Hi all, So I've been thrown into developer hell, with the assignment "Here's $formerprogrammers's project, it doesn't work, fix it, oh yeah, and there's a tight deadline" It seems like...
7
by: Daz | last post by:
Hi. I am trying to select data from two separate MySQL tables, where I cannot use join, but when I put the two select queries into a single query, I get an error telling me to check my syntax. Both...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
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
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?
1
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 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.