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

Select one row from MySQL table

11
Hi all and Merry Christmas!

I wanted to ask how would I deal with the following problem:

Say I have a table [TABLE1]:
customerid name
1 nick
2 george
3 harry

and a [TABLE2]:
number car
1 Lotus
2 BMW
2 FERRARI
2 LADA
3 Lamporgini

If I want to see george's car, I would write: SELECT car from TABLE2 where number ='2';
and I would get :
BWM
FERRARI
LADA

The thing is that I don't want to get 3 lines, but just one, where each record will be separated e.g. by TAB.
But with mysql_fetch_array I will get 3 lines. I must somehow "check" for each person if he has more than one cars,
and show them in one row, not in multiple rows.

I am stuck!
Dec 30 '05 #1
3 31037
Niheel
2,460 Expert Mod 2GB
Merry Christmas and Happy New Years! Only one day away from 2006.

Regrading your problem:

You can limit the results by using LIMIT.

In your case the example would look like:
SELECT car FROM table2 WHERE number='3' LIMIT 1

You can change that 1 to what ever number of results you like. Hope that helped you out. If not reply back.
Dec 30 '05 #2
At the moment i can't to check up - what if request is will be like this?

SELECT car FROM table2 WHERE number = '2' GROUP by number
Jan 9 '06 #3
Niheel
2,460 Expert Mod 2GB
KStirig, did the solution help you answer the question? Are you trying to also group the results like:

lotus
bmw, ferrari, lada
lamborghini
Jan 9 '06 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Alex Glaros | last post by:
I need help on my basic table connection syntaxt using PHP. I call the php from a web browser url_name_goes_here/test.php. The database name is tennis and the user name is tennis. If I type...
21
by: John Fabiani | last post by:
Hi, I'm a newbie and I'm attempting to learn howto create a select statement. When I use >>> string1='18 Tadlock Place' >>> cursor.execute("SELECT * FROM mytest where address = %s",string1) All...
0
by: Verdon vaillancourt | last post by:
Hi :) I'm not even sure if I'm naming the question correctly. I hope I can ask/explain it clearly enough to get a hint ;) Essentially... 1) I have a table of portfolio 'pieces', each row of...
0
by: James Fryer | last post by:
Assuming a legal SELECT statement, this works fine: CREATE TABLE Foo SELECT ... but this does not: CREATE TABLE Foo (SELECT ...) This is a problem for me as I'd like to use the output of...
0
by: Hans Maurer | last post by:
>Description: We're running our current TTS application with MySQL (on Unix). All database, table and column names are in lower-case. However, we need to access this database with a new...
2
by: skidvd | last post by:
Hello: I have just recently converted to using the InnoDB table type so that I can enforce FOREIGN key constraints. I have been using MyISAM tables (accessed via JDBC) successfully for some...
0
by: JB | last post by:
Hey ppl, I'm experiancing a very weird problem with my current Win32(win2k/XP) application. I'm using: * Delphi 7 * ADO * mySQL ODBC 3.51 drivers
4
by: Denis St-Michel | last post by:
Hello All, Hope some Guru will be able to help me with this. Let's take this example table A ------------------------------------------------------------------------------- id | ...
5
by: jayson_13 | last post by:
Hi, I need to implement a counter and i face problem of locking so hope that u guys can help me. I try to do test like this : 1st connection SELECT * FROM nextkey WHERE tblname = 'PLCN'...
17
by: kalamos | last post by:
This statement fails update ded_temp a set a.balance = (select sum(b.ln_amt) from ded_temp b where a.cust_no = b.cust_no and a.ded_type_cd = b.ded_type_cd and a.chk_no = b.chk_no group by...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
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
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
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...

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.