Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Combine 2 MySQL querys
Old 03-24-2010, 06:25 PM Combine 2 MySQL querys
Junior Talker

Posts: 1
Trades: 0
How do i combine these two querys:

1: "SELECT * FROM submenu WHERE submenu.parent NOT IN (select id from topmenu) UNION
SELECT * FROM topmenu"
2: "SELECT * FROM topmenu"

And echo them out in a loop ?
borgen44 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-20-2010, 12:59 AM Re: Combine 2 MySQL querys
idydenka's Avatar
Junior Talker

Posts: 1
Name: idydenka
Trades: 0
hi..
i do like this:

"select a.*,b.* form table1 a,table2 b where (condition)"

i never use union command

and if u want to echo them in a loop
try to use while loop..
because i use to do it ,and it work great



..sorry if this not help you
idydenka is offline
Reply With Quote
View Public Profile
 
Old 04-20-2010, 08:50 AM Re: Combine 2 MySQL querys
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
I'd say that your first query already does that.
The UNION statement is used to join the result of 2 queries, and the 2 queries you join are
1)SELECT * FROM submenu WHERE submenu.parent NOT IN (select id from topmenu)
and
2)
SELECT * FROM topmenu

So, in the result of that query:
Code:
SELECT * FROM submenu WHERE submenu.parent NOT IN  (select id from topmenu)
union
SELECT * FROM topmenu
, and as far as the type and numbers of columns are the same, you will get every rows from topMenu, and every rows from subMenu who does not have a parent defined in topMenu.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Reply     « Reply to Combine 2 MySQL querys
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.36557 seconds with 12 queries