paultaylor01 Posted February 20, 2008 Share Posted February 20, 2008 Hi all. I've got 2 tables: Table A Table B Both tables contain different fields, together with a date field (which has the same name, call it datefield for arguments sake). The tables are not linked or joined in any way. Is it possible to extract and list the contents of the 2 tables, combined, and sorted in datefield sequence? Cheers Paul Quote Link to comment https://forums.phpfreaks.com/topic/92155-multiple-tables/ Share on other sites More sharing options...
php_dave Posted February 20, 2008 Share Posted February 20, 2008 I guess this is a mysql database - this question should really be in the mysql section.. but select a.*, b.* from tableA a, tableB b order by a.datefield, b.datefield ASC is that what you meant Cheers Dave Quote Link to comment https://forums.phpfreaks.com/topic/92155-multiple-tables/#findComment-472037 Share on other sites More sharing options...
fenway Posted February 20, 2008 Share Posted February 20, 2008 You don't want to join the tables in the mysql sense... you can to combine the result, with UNION. Quote Link to comment https://forums.phpfreaks.com/topic/92155-multiple-tables/#findComment-472040 Share on other sites More sharing options...
paultaylor01 Posted February 20, 2008 Author Share Posted February 20, 2008 Thanks for the replies. Forgive me ignorance, but I havn't used UNION before. What is the basic syntax? Thanks Paul Quote Link to comment https://forums.phpfreaks.com/topic/92155-multiple-tables/#findComment-472049 Share on other sites More sharing options...
fenway Posted February 20, 2008 Share Posted February 20, 2008 ( first query ) UNION ( second query ) ORDER BY .... Make sure you have similar numbers of columns, and all the types match up. Quote Link to comment https://forums.phpfreaks.com/topic/92155-multiple-tables/#findComment-472055 Share on other sites More sharing options...
paultaylor01 Posted February 20, 2008 Author Share Posted February 20, 2008 Thanks Fenway. However, let's assume the 2 tables vary widely in terms of number of fields, field-types etc (as they do in this example). Table A has about 20 fields, Table B has about 5. The only 'common' field is the date field which is what I want the output sorted by. I'm reading between the lines that UNION isn't applicable in this case? Is there any other solution? Cheers Paul Quote Link to comment https://forums.phpfreaks.com/topic/92155-multiple-tables/#findComment-472069 Share on other sites More sharing options...
fenway Posted February 20, 2008 Share Posted February 20, 2008 Well, you can specify a column list to match the # and type... but in your case, it sounds like you want them all? If so, you might have to get the "super-ordering" first just with id, table and date, and then feed that back... rather ugly. Quote Link to comment https://forums.phpfreaks.com/topic/92155-multiple-tables/#findComment-472087 Share on other sites More sharing options...
paultaylor01 Posted February 20, 2008 Author Share Posted February 20, 2008 Or I could just combine the 2 tables into 1 - much easier! Thanks for your help. Paul Quote Link to comment https://forums.phpfreaks.com/topic/92155-multiple-tables/#findComment-472090 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.