/    Sign up×
Community /Pin to ProfileBookmark

If Exists or any other…

Hi

I do have in my database the following tables:

inter_main_usa
inter_main_uk

Both tables have the some structure.

But in the first I have data
In the second I do not have any data yet

lets assume I have in the inter_main_usa the respective column called vehicles data call “car” but in the inter_main_uk I do not have anything yet at the same column.

How can make to be listed the country that only have “car” in the vehicles column, making sure that when I do introduce bike in the vehicles column of inter_main_uk it lists both countries.

thanks

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@MindzaiFeb 17.2010 — Not sure I follow what you want, but this sounds like you could have a better database structure. Multiple tables with the same schema is always a bad sign. I would suggest having one table, with a foreign key referencing a countries table (containing rows for uk and usa).
Copy linkTweet thisAlerts:
@SrWebDeveloperFeb 17.2010 — Yep.

But if the structure is set, left join can be used to join two tables with connecting records that match plus an extra for each orphan on left:

[CODE]select * from table1 left join table2 on table1.field=table2.field[/CODE]

Or, selecting only orphans from the join (for auditing purposes):

[CODE]select * from table1 left join table2 on table1.field1 = table2.field1 where field2 is NULL;[/CODE]

Left join and is null might help the OP in this instance, depending on their needs. This is general advice and not specific to this request.

-jim
×

Success!

Help @JoseSilva spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.24,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...