473,407 Members | 2,598 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,407 software developers and data experts.

how to have these two consequent queries become a single one by 'join' in mysql

--------------------------------------------------------- table_info
| id | age | first_name | last_name |
---------------------------------------------------------
| 10 | 21 | tom | ben |
---------------------------------------------------------

---------------------------------------------------------
table_working_hr
| id | coming_date | work_hour |
---------------------------------------------------------
10 | 12 | 4 |
---------------------------------------------------------
10 | 11 | 4 |
---------------------------------------------------------
10 | 22 | 6 | <-------the
will be the final result.
---------------------------------------------------------
$result= mysql_query(" select * from table_info where first_name =
'tom' ");
$id = $result['id'];
mysql_query(" select * from table_working_hr where id='$id' AND
coming_date 20 ");

Can I get the result with a single query (with some advanced query
like join )?

Jul 22 '07 #1
1 1264
While the city slept, newbie (mi******@yahoo.com) feverishly typed...

[...]
$result= mysql_query(" select * from table_info where first_name =
'tom' ");
$id = $result['id'];
mysql_query(" select * from table_working_hr where id='$id' AND
coming_date 20 ");

Can I get the result with a single query (with some advanced query
like join )?
mysql_query("select twh.* from `table_working_hr` twh inner join
`table_info` ti on twh.id = ti.id where ti.first_name = 'tom' and
twh.coming_date 20");

Hope that helps,
Nige

--
Nigel Moss http://www.nigenet.org.uk
Mail address will bounce. ni***@DOG.nigenet.org.uk | Take the DOG. out!
"Your mother ate my dog!", "Not all of him!"
Jul 22 '07 #2

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

Similar topics

0
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
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...
1
by: Ninjaboy | last post by:
I'm trying to run NOT EXISTS or NOT IN query to find out wich records in one table do not match the other and mysql just gives me weird error. QUERY: SELECT cust_id FROM customers WHERE...
9
by: mfyahya | last post by:
Hi, I'm new to databases :) I need help speeding up select queries on my data which are currently taking 4-5 seconds. I set up a single large table of coordinates data with an index on the fields...
5
by: Kevin Myers | last post by:
In MS Access 2000 I am developing a form for editing and viewing the combined data from half a dozen tables. When I include all but one of the tables in the source query for the form, everything...
3
by: Zlatko Matić | last post by:
Hello. I'm wondernig what is happennig whith saved pass-through queries nested in regular JET query if regular JET query just filtrates result by start/end date...Does pass-through query first...
3
by: iksrazal | last post by:
Hi all, I'm hoping someone on this forum can help me. I use hibernate with java to access mysql. We are trying to upgrade from 4.1.15 non-inndb, to 5.0.18 with innodb. Hibernate makes a 'create...
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: bhavinnaik | last post by:
Hi I am new to the IT enviro...although i've used QSL query for a while now but on simple or single queries. Here is the problem... I've got two queries looking at a set of tables to extract the...
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?
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
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.