Byte Forums
»
Computing
»
Programming
»
Web Programming
Advanced SQL
|
|
|
Advanced SQL
|
|
08-02-2007, 03:29 PM
Post: #1
|
|||
|
|||
|
Advanced SQL
Okay.
I need to find a SQL query which can output the fields i want out of 2 tables in order. So basically its like... SELECT f_name AS fname FROM db "and" select fname FROM leads "which are" ORDER BY fn ASC in both tables Field names are different in both tables also.... Thanks. ByteForums: Rules | Challenges | PHP Tutorials | Myspace | Youtube
|
|||
|
08-02-2007, 03:43 PM
Post: #2
|
|||
|
|||
|
RE: Advanced SQL
PHP Code: $result = mysql_query("SELECT * FROM `table1`,`table2`");something like that? ![]() Web Hosting | Shoutcast Servers | Custom Solutions |
|||
|
08-02-2007, 04:20 PM
(This post was last modified: 08-02-2007 06:09 PM by Birdie.)
Post: #3
|
|||
|
|||
|
RE: Advanced SQL
Why didnt i think of that, the ordering works perfect with it. I thought that would of done inside orderings but it doesnt.
Thanks. Ah EDIT: Er, does anyone know how to select these tables like above and use a SELECT f_name as fn for only 1 table so all data seems to be from 1 structure? Thanks again. EDIT 2: Well.. i normally try and get away from UNION but heres the SQL i figured should work... but not all firstnames are ouputted and i dont have a clue why? Code: SELECT f_name as fn2 from db UNION select fn AS fn2 FROM leadsByteForums: Rules | Challenges | PHP Tutorials | Myspace | Youtube
|
|||
|
08-03-2007, 03:48 PM
Post: #4
|
|||
|
|||
|
RE: Advanced SQL
erm, are the firstnames that arnt displayed all in a certain table?
![]() Web Hosting | Shoutcast Servers | Custom Solutions |
|||
|
08-03-2007, 04:15 PM
Post: #5
|
|||
|
|||
|
RE: Advanced SQL
Doesn't matter... guess what it was...
UNION ALL.... Thanks anyway. ByteForums: Rules | Challenges | PHP Tutorials | Myspace | Youtube
|
|||
|
08-15-2007, 05:42 AM
Post: #6
|
|||
|
|||
|
RE: Advanced SQL
well if it was me, I just use simple query, something like SELECT * FROM tablename WHERE blah blah blah
then i just do it twice, one sorted with the firstname and then with the lastname (surname)... save them to variables $queryresult and $queryresult2... then to sort on 2 tables I do the nobish things cause I'm a newb ![]() print "<table><tr><td>firstname</td><td>lastname</td></tr>"; while ($arrayresult = mysql_fetch_array($queryresult)) { print "<tr><td>$arrayresult[firstname]</td><td>$arrayresult[lastname]</td></tr>"; } print "</table><table><tr><td>firstname</td><td>lastname</td></tr>"; while ($arrayresult = mysql_fetch_array($queryresult2)) { print "<tr><td>$arrayresult[firstname]</td><td>$arrayresult[lastname]</td></tr>"; } print "</table>"; it has 2 querys and 2 arrays but it gives the same result I think well don't laugh now cause I just started PHP and MySQL 2months ago so I'm a newb!
|
|||
|
08-15-2007, 02:26 PM
Post: #7
|
|||
|
|||
|
RE: Advanced SQL
The order wouldnt be right thought you see. It would order 1 set then start again on the 2nd set.
ByteForums: Rules | Challenges | PHP Tutorials | Myspace | Youtube
|
|||
|
« Next Oldest | Next Newest »
|




![[Image: birdie312.png]](http://miniprofile.xfire.com/bg/sh/type/0/birdie312.png)





