Welcome Guest, Not a member yet? Register   Sign In
MySQL question: 2 queries in 1
#4

[eluser]xwero[/eluser]
Mysql only has subqueries from version 5 but many other databases have it i believe.

But what you are trying to do is something like
Code:
select id,username from tbl_user;
select hobby_id from tbl_user_hobbies where user_id=id;

I don't know if it can be done without redundant data using one query but it's possible with a join
Code:
select t1.username,t2.hobby_id from tbl_user as t1 right join tbl_user_hobbies on t2.userid=t1.id;


Messages In This Thread
MySQL question: 2 queries in 1 - by El Forum - 11-05-2007, 10:52 AM
MySQL question: 2 queries in 1 - by El Forum - 11-05-2007, 10:57 AM
MySQL question: 2 queries in 1 - by El Forum - 11-05-2007, 10:58 AM
MySQL question: 2 queries in 1 - by El Forum - 11-05-2007, 11:12 AM
MySQL question: 2 queries in 1 - by El Forum - 11-05-2007, 12:08 PM
MySQL question: 2 queries in 1 - by El Forum - 11-05-2007, 12:23 PM
MySQL question: 2 queries in 1 - by El Forum - 11-05-2007, 02:12 PM
MySQL question: 2 queries in 1 - by El Forum - 11-05-2007, 03:12 PM
MySQL question: 2 queries in 1 - by El Forum - 11-05-2007, 03:22 PM



Theme © iAndrew 2016 - Forum software by © MyBB