![]() |
Selecting from two tables
Okay so I pretty much know nothing of this, but what I'm trying to do is this:
I want to select all columns from a table called "updates", and one column (named "image") from a table called "portfolio". I've been trying some things but I don't really have a clue and all I'm getting are errors. When I look up on how to select information from to tables, I find all things like joining them with inner join and left join etc. But I was wondering what I need to do in this case and if these things are necessary. |
I think you need to have something common with both tables in order to do this.
Like "ON TableA.name = TableB.name". With out it I keep coming up with way too much information. |
Mh but they have nothing in common, that's not my meaning because I just have this page, on which I want to display updates (just a date and the title of the update, which I have a table for). And on the same page I want to make a div in which random images from another table are displayed.
Do I maybe just have to make a new query for that or something? Because I can't really see how to link those two. |
Well, I know one way to do it, but it would *NOT* guarantee that each record from your primary table would get a *UNIQUE* image from the second table.
In other words, if you showed 10 dates and titles, you might find that you would get 7 different images, with 3 of the images repeated. etc. And I do see another more complex way to do this where each date/title would get a unique image *provided* there are at least as many image records as there are data/title records. But, really, it would probably be easier to just do this as two separate queries and let your PHP/ASP/JSP/whatever code get one record from each table. You could do both Code:
SELECT * FROM dates_and_titles ORDER BY something;But if you really need a MySQL solution we could make one. |
The easy way that doesn't guarantee unique images is fine. But I'm a bit confused. To get my records from the updates table I use this
Code:
$query = "SELECT *FROM updates ORDER BY date DESC";Code:
SELECT images FROM portfolio ORDER BY RAND(); |
Two separate queries.
I don't use PHP, but it will be *SOMETHING* like this: Code:
|
| All times are GMT +1. The time now is 08:09 AM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.