hi. i have two tables.
table one ("users") contains two columns, "user_id", and "user_name"
table two ("spam") contains three columns "msg_id","user_id", and "msg"
basically, i want to retrieve all the "spam" entries, but instead of
displaying the user_id, i want it to show the user_name, from table
one. (using php)
i'm assuming i need to use this JOIN thing, but i've never used it
before. any help? 4 4335
Mark wrote:
hi. i have two tables.
table one ("users") contains two columns, "user_id", and "user_name"
table two ("spam") contains three columns "msg_id","user_id", and "msg"
basically, i want to retrieve all the "spam" entries, but instead of
displaying the user_id, i want it to show the user_name, from table
one. (using php)
i'm assuming i need to use this JOIN thing, but i've never used it
before. any help?
err..by sort of guessing, i came up with "SELECT * FROM spam LEFT JOIN
users USING (user_id)" which seems to work alright. is that how you're
supposed to do it?
Mark wrote:
hi. i have two tables.
table one ("users") contains two columns, "user_id", and "user_name"
table two ("spam") contains three columns "msg_id","user_id", and "msg"
basically, i want to retrieve all the "spam" entries, but instead of
displaying the user_id, i want it to show the user_name, from table
one. (using php)
i'm assuming i need to use this JOIN thing, but i've never used it
before. any help?
SELECT users.user_name,spam.msg_id ,spam.msg FROM users.spam WHERE
spam.user_id = users..user_id
Mark wrote:
err..by sort of guessing, i came up with "SELECT * FROM spam LEFT JOIN
users USING (user_id)" which seems to work alright.
It might work a bit faster as following:
SELECT * FROM spam JOIN users USING (user_id);
You would use LEFT JOIN if you thought that there might be no entries in
the users table matching the user_id given in the spam table. I would
expect in your case that there should be a user in all such cases, so a
simple inner join would be fine. Inner joins often run quicker than
outer joins.
Regards,
Bill K.
Bill Karwin wrote:
Mark wrote:
err..by sort of guessing, i came up with "SELECT * FROM spam LEFT JOIN
users USING (user_id)" which seems to work alright.
It might work a bit faster as following:
SELECT * FROM spam JOIN users USING (user_id);
You would use LEFT JOIN if you thought that there might be no entries in
the users table matching the user_id given in the spam table. I would
expect in your case that there should be a user in all such cases, so a
simple inner join would be fine. Inner joins often run quicker than
outer joins.
Regards,
Bill K.
ohhh.. i see. thank you! this helps. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: B. Fongo |
last post by:
I learned MySQL last year without putting it into action; that is why
I face trouble in formulating my queries. Were it a test, then you
would have passed it, because your queries did help me...
|
by: Soefara |
last post by:
Dear Sirs,
I am experiencing strange results when trying to optimize a LEFT JOIN
on 3 tables using MySQL.
Given 3 tables A, B, C such as the following:
create table A (
uniqueId int not...
|
by: TeleTech1212 |
last post by:
I am trying to select specific columns from multiple tables based on a
common identifier found in each table.
For example, the three tables:
PUBACC_AC
PUBACC_AM
PUBACC_AN
each have a...
|
by: Matt |
last post by:
Hello
I have to tables ar and arb, ar holds articles and a swedish
description, arb holds descriptions in other languages.
I want to retreive all articles that match a criteria from ar and...
|
by: Anthony Robinson |
last post by:
I was actually just wondering if someone could possibly take a look
and tell me what I may be doing wrong in this query? I keep getting
ambiguous column errors and have no idea why...?
Thanks in...
|
by: dskillingstad |
last post by:
I would really appreciate someone's help on this, or at least point me
in the right direction....
I'm working on a permit database that contains 12 tables, and rather
than list all of the...
|
by: Bennett Haselton |
last post by:
I know how to create a DataAdapter that loads data from a data source
into a table in a typed DataSet, and how to set the DataSource and
DataMember properties of a DataGrid so that at run time it...
|
by: Shanimal |
last post by:
I would like to know how to join 2 queries so that the results of these
2 queries show up in the same query:
SELECT b.bios_serial_number FROM bios b:
SELECT s.system_name FROM system s;
...
|
by: MP |
last post by:
Hi
trying to begin to learn database using vb6, ado/adox, mdb format, sql
(not using access...just mdb format via ado)
i need to group the values of multiple fields
- get their possible...
|
by: Zeff |
last post by:
Hi all,
I have a relational database, where all info is kept in separate tables
and just the id's from those tables are stored in one central table
(tblMaster)...
I want to perform a query, so...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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...
|
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: 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...
|
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...
|
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,...
|
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: 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...
|
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...
| |